home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / tex / webtp55.zip / TPWEBMAN.TEX (.txt) < prev    next >
LaTeX Document  |  1989-12-05  |  98KB  |  1,677 lines

  1. % This is TpWebMan.TeX as of 28-Nov-1989 PS
  2. % All of the material except Appendix I is taken verbatim
  3. % from Donald Knuth's original file "webman.tex"
  4. \input webmac
  5. \parskip 0pt plus 1pt
  6. \def\RA{\char'31 } % right arrow
  7. \def\hang{\hangindent 4em\ignorespaces}
  8. \font\ninerm=cmr9
  9. \font\ninett=cmtt9
  10. \font\eighttt=cmtt8
  11. \let\mc=\ninerm % medium caps for names like SAIL
  12. \def\PASCAL{Pascal}
  13. \font\chged=cmss10           % TPWEB
  14. \def\TP{Turbo Pascal 5.5}    % TPWEB
  15. \def\TGLTP{Tangle TP55}      % TPWEB
  16. \font\quoterm=cmssq8
  17. \font\quoteit=cmssqi8
  18. \def\pb{\.{|...|}}
  19. \def\lpile{\def\cr{\hfill\endline}\matrix} % I only use \lpile by itself
  20. \outer\def\section #1.{\penalty-50\vskip 12pt plus 3pt minus 3pt
  21.   \noindent{\bf #1.}\quad\ignorespaces}
  22. \def\titlepage{T}
  23. \def\lheader{\mainfont\the\pageno\hfill\sc\runninghead\hfill}
  24. \def\rheader{\hfill\sc\runninghead\hfill\mainfont\the\pageno}
  25. \def\runninghead{{\tentt WEB} USER MANUAL}
  26. % This verbatim mode assumes that no ? appears in the text being copied.
  27. \def\verbatim{\begingroup
  28.   \def\do##1{\catcode`##1=12 } \dospecials
  29.   \parskip 0pt \parindent 0pt
  30.   \catcode`\ =13 \catcode`\^^M=13
  31.   \tt \catcode`\?=0 \verbatimdefs \verbatimgobble}
  32. {\catcode`\^^M=13{\catcode`\ =13\gdef\verbatimdefs{\def^^M{\ \par}\let =\ }} %
  33.   \gdef\verbatimgobble#1^^M{}}
  34. \centerline{\titlefont The {\ttitlefont WEB} System
  35.   of Structured Documentation}
  36.  \centerline{\chged for \TP} % TPWEB
  37. \vskip 15pt plus 3pt minus 3pt
  38. \noindent This memo describes how to write programs in the
  39. \.{WEB} language; and it also includes the full \.{WEB} documentation for
  40. \.{WEAVE} and \.{TANGLE}, the programs that read \.{WEB} input and produce
  41. \TeX\ and \PASCAL\ output, respectively. The philosophy behind \.{WEB} is
  42. that an experienced system programmer, who wants to provide the best
  43. possible documentation of his or her software products, needs two things
  44. simultaneously:  a language like \TeX\ for formatting, and a language like
  45. \PASCAL\ for programming. Neither type of language can provide the best
  46. documentation by itself; but when both are appropriately combined, we
  47. obtain a system that is much more useful than either language separately.
  48. The structure of a software program may be thought of as a ``web'' that is
  49. made up of many interconnected pieces. To document such a program, we want
  50. to explain each individual part of the web and how it relates to its
  51. neighbors. The typographic tools provided by \TeX\ give us an opportunity
  52. to explain the local structure of each part by making that structure
  53. visible, and the programming tools provided by \PASCAL\ make it possible
  54. for us to specify the algorithms formally and unambiguously. By combining
  55. the two, we can develop a style of programming that maximizes our ability
  56. to perceive the structure of a complex piece of software, and at the same
  57. time the documented programs can be mechanically translated into a working
  58. software system that matches the documentation.
  59. Since \.{WEB} is an experimental system developed for internal use within
  60. the \TeX\ project at Stanford, this report is rather terse, and it assumes
  61. that the reader is an experienced programmer who is highly motivated to
  62. read a detailed description of \.{WEB}'s rules. Furthermore, even if a
  63. less terse manual were to be written, the reader would have to be warned
  64. in advance that \.{WEB} is not for beginners and it never will be: The
  65. user of \.{WEB} must be familiar with both \TeX\ and \PASCAL. When one
  66. writes a \.{WEB} description of a software system, it is possible to make
  67. mistakes by breaking the rules of \.{WEB} and/or the rules of \TeX\ and/or
  68. the rules of \PASCAL. In practice, all three types of errors will occur,
  69. and you will get different error messages from the different language
  70. processors. In compensation for the sophisticated expertise needed to cope
  71. with such a variety of languages, however, experience has shown that
  72. reliable software can be created quite rapidly by working entirely in
  73. \.{WEB} from the beginning; and the documentation of such programs seems
  74. to be better than the documentation obtained by any other known method.
  75. Thus, \.{WEB} users need to be highly qualified, but they can get some
  76. satisfaction and perhaps even a special feeling of accomplishment when
  77. they have successfully created a software system with this method.
  78. To use \.{WEB}, you prepare a file called \.{COB.WEB} (say), and then you
  79. apply a system program called \.{WEAVE} to this file, obtaining an output
  80. file called \.{COB.TEX}.  When \TeX\ processes \.{COB.TEX}, your output
  81. will be a ``pretty printed'' version of \.{COB.WEB} that takes appropriate
  82. care of typographic details like page layout and the use of indentation,
  83. italics, boldface, etc.; this output will contain extensive cross-index
  84. information that is gathered automatically. You can also submit the same
  85. file \.{COB.WEB} to another system program called \.{TANGLE}, which will
  86. produce a file \.{COB.PAS} that contains the \PASCAL\ code of your \.{COB}
  87. program. The \PASCAL\ compiler will convert \.{COB.PAS} into
  88. machine-language instructions corresponding to the algorithms that were so
  89. nicely formatted by \.{WEAVE} and \TeX. Finally, you can (and should)
  90. delete the files \.{COB.TEX} and \.{COB.PAS}, because \.{COB.WEB} contains
  91. the definitive source code. Examples of the behavior of \.{WEAVE} and
  92. \.{TANGLE} are appended to this manual.
  93. Besides providing a documentation tool, \.{WEB} enhances the \PASCAL\
  94. language by providing a rudimentary macro capability together with the
  95. ability to permute pieces of the program text, so that a large system can
  96. be understood entirely in terms of small modules and their local
  97. interrelationships.  The \.{TANGLE} program is so named because it takes a
  98. given web and moves the modules from their web structure into the order
  99. required by \PASCAL; the advantage of programming in \.{WEB} is that the
  100. algorithms can be expressed in ``untangled'' form, with each module
  101. explained separately.  The \.{WEAVE} program is so named because it takes
  102. a given web and intertwines the \TeX\ and \PASCAL\ portions contained in
  103. each module, then it knits the whole fabric into a structured document.
  104. (Get it? Wow.)  Perhaps there is some deep connection here with the fact
  105. that the German word for ``weave'' is ``{\it web\/}'', and the
  106. corresponding Latin imperative is ``{\it texe\/}''!
  107. It is impossible to list all of the related work that has influenced the
  108. design of \.{WEB}, but the key contributions should be mentioned
  109. here.\quad (1)~Myrtle Kellington, as executive editor for ACM
  110. publications, developed excellent typographic standards for the
  111. typesetting of Algol programs during the 1960s, based on the original
  112. designs of Peter Naur; the subtlety and quality of this influential work
  113. can be appreciated only by people who have seen what happens when other
  114. printers try to typeset Algol without the advice of ACM's copy
  115. editors.\quad(2)~Bill McKeeman introduced a program intended to automate
  116. some of this task [Algorithm 268, ``Algol~60 reference language editor,''
  117. {\sl CACM \bf8} (1965), 667--668]; and a considerable flowering of such
  118. programs has occurred in recent years [see especially Derek Oppen,
  119. ``Prettyprinting,'' {\sl ACM TOPLAS \bf2} (1980), 465--483; G.~A. Rose and
  120. J. Welsh, ``Formatted programming languages,'' {\sl SOFTWARE Practice
  121. \char`\&\ Exper.\ \bf11} (1981), 651--669].\quad(3)~The top-down style of
  122. exposition encouraged by \.{WEB} was of course chiefly influenced by Edsger
  123. Dijkstra's essays on structured programming in the late 1960s. The less
  124. well known work of Pierre-Arnoul de Marneffe [``Holon programming: A
  125. survey,'' Univ.\ de Liege, Service Informatique, Liege, Belgium, 1973; 135
  126. pp.\null] also had a significant influence on the author as \.{WEB} was
  127. being formulated.\quad(4)~Edwin Towster has proposed a similar style of
  128. documentation in which the programmer is supposed to specify the relevant
  129. data structure environment in the name of each submodule [``A convention
  130. for explicit declaration of environments and top-down refinement of
  131. data,'' {\sl IEEE Trans.\ on Software Eng.\ \bf SE--5} (1979), 374--386];
  132. this requirement seems to make the documentation a bit too verbose,
  133. although experience with \.{WEB} has shown that any unusual control
  134. structure or data structure should definitely be incorporated into the
  135. module names on psychological grounds.\quad(5)~Discussions with Luis
  136. Trabb~Pardo in the spring of 1979 were extremely helpful for setting up a
  137. prototype version of \.{WEB} that was called \.{DOC}.\quad (6)~Ignacio
  138. Zabala's extensive experience with \.{DOC}, in which he created a full
  139. implementation of \TeX\ in \PASCAL\ that was successfully transported to
  140. many different computers, was of immense value while \.{WEB} was taking
  141. its present form.\quad(7)~David~R. Fuchs made several crucial suggestions
  142. about how to make \.{WEB} more portable; he and Arthur~L. Samuel
  143. coordinated the initial installations of \.{WEB} on dozens of computer
  144. systems, making changes to the code so that it would be acceptable to
  145. a wide variety of \PASCAL\ compilers.\quad(8)~The name \.{WEB} itself
  146. was chosen in honor of my wife's mother, Wilda Ernestine Bates.
  147. The appendices to this report contain complete \.{WEB} programs for the
  148. \.{WEAVE} and \.{TANGLE} processors. A study of these examples, together
  149. with an attempt to write \.{WEB} programs by yourself, is the best way
  150. to understand why \.{WEB} has come to be like it is.
  151. \section General rules.
  152. A \.{WEB} file is a long string of text that has been divided into
  153. individual lines. The exact line boundaries are not terribly crucial, and
  154. a programmer can pretty much chop up the \.{WEB} file in whatever way seems
  155. to look best as the file is being edited; but string constants and control
  156. texts must end on the same line on which they begin, since this convention
  157. helps to keep errors from propagating.  The end of a line means
  158. the same thing as a blank space.
  159. Two kinds of material go into \.{WEB} files: \TeX\ text and \PASCAL\ text.
  160. A programmer writing in \.{WEB} should be thinking both of the
  161. documentation and of the \PASCAL\ program that he or she is creating;
  162. i.e., the programmer should be instinctively aware of the different
  163. actions that \.{WEAVE} and \.{TANGLE} will perform on the \.{WEB} file.
  164. \TeX\ text is essentially copied without change by \.{WEAVE}, and it is
  165. entirely deleted by \.{TANGLE}, since the \TeX\ text is ``pure
  166. documentation.'' \PASCAL\ text, on the other hand, is formatted by
  167. \.{WEAVE} and it is shuffled around by \.{TANGLE}, according to rules that
  168. will become clear later. For now the important point to keep in mind is
  169. that there are two kinds of text. Writing \.{WEB} programs is something
  170. like writing \TeX\ documents, but with an additional ``\PASCAL\ mode''
  171. that is added to \TeX's horizontal mode, vertical mode, and math mode.
  172. A \.{WEB} file is built up from units called {\sl modules\/} that are more
  173. or less self-contained.  Each module has three parts:
  174. \yskip\item{1)} A \TeX\ part, containing explanatory material about what
  175. is going on in the module.
  176. \item{2)} A definition part, containing macro definitions that serve as
  177. abbreviations for \PASCAL\ constructions that would be less comprehensible
  178. if written out in full each time.
  179. \item{3)} A \PASCAL\ part, containing a piece of the program that
  180. \.{TANGLE} will produce. This \PASCAL\ code should ideally be about a
  181. dozen lines long, so that it is easily comprehensible as a unit and so
  182. that its structure is readily perceived.
  183. \yskip\noindent The three parts of each module must appear in this order;
  184. i.e., the \TeX\ commentary must come first, then the definitions, and
  185. finally the \PASCAL\ code. Any of the parts may be empty.
  186. \eject % page break inserted Dec 88
  187. A module begins with the pair of symbols `\.{@\ }' or `\.{@*}', where
  188. `\.{\ }' denotes a blank space. A module ends
  189. at the beginning of the next module (i.e., at the next
  190. `\.{@\ }' or `\.{@*}'), or at the end of the file, whichever comes first.
  191. The \.{WEB} file may also contain material that is not part of any module
  192. at all, namely the text (if any) that occurs before the first module.
  193. Such text is said to be ``in limbo''; it is ignored by \.{TANGLE}
  194. and copied essentially verbatim by \.{WEAVE}, so its function is to
  195. provide any additional formatting instructions that may be desired in the
  196. \TeX\ output. Indeed, it is customary to begin a \.{WEB} file with
  197. \TeX\ code in limbo that loads special fonts, defines special macros,
  198. changes the page sizes, and/or produces a title page.
  199. Modules are numbered consecutively, starting with 1; these numbers appear
  200. at the beginning of each module of the \TeX\ documentation, and they appear
  201. as bracketed comments at the beginning of the code generated by that
  202. module in the \PASCAL\ program.
  203. Fortunately, you never mention these numbers yourself when you are writing
  204. in \.{WEB}. You just say `\.{@\ }' or `\.{@*}' at the beginning of each
  205. new module, and the numbers are supplied automatically by \.{WEAVE} and
  206. \.{TANGLE}. As far as you are concerned, a module has a
  207. name instead of a number; such a name is specified by writing
  208. `\.{@<}' followed by \TeX\ text followed by `\.{@>}'. When \.{WEAVE}
  209. outputs a module name, it replaces the `\.{@<}' and `\.{@>}' by
  210. angle brackets and inserts the module number in small type. Thus, when you
  211. read the output of \.{WEAVE} it is easy to locate any module that is
  212. referred to in another module.
  213. For expository purposes, a module name should be a good description of the
  214. contents of that module, i.e., it should stand for the abstraction
  215. represented by the module; then the module can be ``plugged into'' one or
  216. more other modules so that the unimportant details of its inner workings
  217. are suppressed.  A module name therefore ought to be long enough to convey
  218. the necessary meaning. Unfortunately, however, it is laborious to type
  219. such long names over and over again, and it is also difficult to specify a
  220. long name twice in exactly the same way so that \.{WEAVE} and \.{TANGLE}
  221. will be able to match the names to the modules. Therefore a module name
  222. can be abbreviated after its first appearance in the \.{WEB} file, by
  223. typing `\.{@<$\alpha$...@>}', where $\alpha$ is any string that is a prefix of
  224. exactly one module name that appears in the file. For example, `\.{@<Clear
  225. the arrays@>}' can be abbreviated to `\.{@<Clear...@>}' if no other module
  226. name begins with the five letters `\.{Clear}'. Module names must otherwise
  227. match character for character, except that consecutive blank spaces and/or
  228. tab marks are treated as equivalent to single spaces, and such spaces are
  229. deleted at the beginning and end of the name. Thus, `\.{@< Clear { }the
  230. arrays @>}' will also match the name in the previous example.
  231. We have said that a module begins with `\.{@\ }' or `\.{@*}', but we
  232. didn't say how it gets divided up into a \TeX\ part, a definition part,
  233. and a \PASCAL\ part. The definition part begins with the first appearance
  234. of `\.{@d}' or `\.{@f}' in the module, and the \PASCAL\ part begins with
  235. the first appearance of `\.{@p}' or `\.{@<}'. The latter option `\.{@<}'
  236. stands for the beginning of a module name, which is the name of the module
  237. itself. An equals sign (\.=) must follow the `\.{@>}' at the end of this
  238. module name; you are saying, in effect, that the module name stands for
  239. the \PASCAL\ text that follows, so you say `$\langle\,$module
  240. name$\,\rangle=\null$\PASCAL\ text'. Alternatively, if the \PASCAL\ part
  241. begins with `\.{@p}' instead of a module name, the current module is said
  242. to be {\sl unnamed}. Note that module names cannot appear in the
  243. definition part of a module, because the first `\.{@<}' in a module
  244. signals the beginning of its \PASCAL\ part.  Any number of module names
  245. might appear in the \PASCAL\ part, however, once it has started.
  246. The general idea of \.{TANGLE} is to make a \PASCAL\ program out of these
  247. modules in the following way: First all the \PASCAL\ parts of unnamed
  248. modules are copied down, in order; this constitutes the initial
  249. approximation $T_0$ to the text of the program. (There should be at least
  250. one unnamed module, otherwise there will be no program.) Then all module
  251. names that appear in the initial text $T_0$ are replaced by the \PASCAL\
  252. parts of the corresponding modules, and this substitution process
  253. continues until no module names remain. Then all defined macros are
  254. replaced by their equivalents, according to certain rules that are
  255. explained later. The resulting \PASCAL\ code is ``sanitized'' so that it
  256. will be acceptable to an average garden-variety \PASCAL\ compiler; i.e.,
  257. lowercase letters are converted to uppercase, long identifiers are
  258. chopped, and the lines of the output file are constrained to be at most 72
  259. characters long.  All comments will have been removed from this \PASCAL\
  260. program except for the meta-comments delimited by `\.{@\{}' and
  261. `\.{@\}}', as explained below, and except for the module-number comments
  262. that point to the source location where each piece of the program text
  263. originated in the \.{WEB} file.
  264. If the same name has been given to more than one module, the \PASCAL\ text
  265. for that name is obtained by putting together all of the \PASCAL\ parts in
  266. the corresponding modules. This feature is useful, for example, in a
  267. module named `Global variables in the outer block', since one can then
  268. declare global variables in whatever modules those variables are
  269. introduced. When several modules have the same name, \.{WEAVE} assigns the
  270. first module number as the number corresponding to that name, and it
  271. inserts a note at the bottom of that module telling the reader to `See
  272. also sections so-and-so'; this footnote gives the numbers of all the other
  273. modules having the same name as the present one. The \PASCAL\ text
  274. corresponding to a module is usually formatted by \.{WEAVE} so that the
  275. output has an equivalence sign in place of the equals sign in the \.{WEB}
  276. file; i.e., the output says `$\langle\,$module
  277. name$\,\rangle\equiv\null$\PASCAL\ text'. However, in the case of the second
  278. and subsequent appearances of a module with the same name, this `$\equiv$'
  279. sign is replaced by `$\mathrel+\equiv$', as an indication that the \PASCAL\
  280. text that follows is being appended to the \PASCAL\ text of another
  281. module.
  282. The general idea of \.{WEAVE} is to make a \.{TEX} file from the \.{WEB}
  283. file in the following way: The first line of the \.{TEX} file will be
  284. `\.{\\input webmac}'; this will cause \TeX\ to read in the macros that
  285. define \.{WEB}'s documentation conventions. The next lines of the file
  286. will be copied from whatever \TeX\ text is in limbo before the first
  287. module.  Then comes the output for each module in turn, possibly
  288. interspersed with end-of-page marks.  Finally, \.{WEAVE} will generate a
  289. cross-reference index that lists each module number in which each \PASCAL\
  290. identifier appears, and it will also generate an alphabetized list
  291. of the module names, as well as a table of contents that
  292. shows the page and module numbers for each ``starred'' module.
  293. What is a ``starred'' module, you ask? A module that begins with `\.{@*}'
  294. instead of `\.{@\ }' is slightly special in that it denotes a new major
  295. group of modules. The `\.{@*}' should be followed by the title of this
  296. group, followed by a period. Such modules will always start on a new page
  297. in the \TeX\ output, and the group title will appear as a running headline
  298. on all subsequent pages until the next starred module. The title will also
  299. appear in the table of contents, and in boldface type at the beginning of
  300. its module. Caution:  Do not use \TeX\ control sequences in such titles,
  301. unless you know that the \.{webmac} macros will do the right thing with
  302. them. The reason is that these titles are converted to uppercase when
  303. they appear as running heads, and they are converted to boldface when they
  304. appear at the beginning of their modules, and they are also written out to
  305. a table-of-contents file used for temporary storage while \TeX\ is
  306. working; whatever control sequences you use must be meaningful in all
  307. three of these modes.
  308. The \TeX\ output produced by \.{WEAVE} for each module consists of
  309. the following: First comes the module number (e.g., `\.{\\M123.}'
  310. at the beginning of module 123, except that `\.{\\N}' appears in place of
  311. `\.{\\M}' at the beginning of a starred module). Then comes the
  312. \TeX\ part of the module, copied almost verbatim except as noted
  313. below. Then comes the definition part and the \PASCAL\ part, formatted
  314. so that there will be a little extra space between them if both are
  315. nonempty. The definition and \PASCAL\ parts are obtained by inserting
  316. a bunch of funny looking \TeX\ macros into the \PASCAL\ program; these
  317. macros handle typographic details about fonts and proper math spacing,
  318. as well as line breaks and indentation.
  319. When you are typing \TeX\ text, you will probably want to make frequent
  320. reference to variables and other quantities in your \PASCAL\ code, and you
  321. will want those variables to have the same typographic treatment
  322. when they appear in your text as when they appear in your
  323. program.  Therefore the \.{WEB} language allows you to get the effect of
  324. \PASCAL\ editing within \TeX\ text, if you place `\.|' marks before and
  325. after the \PASCAL\ material. For example, suppose you want to say something
  326. like this:
  327. $$\hbox{The characters are placed into \\{buffer}, which is a
  328. \&{packed} \&{array} $[1\to\|n]$ \&{of} \\{char}.}$$
  329. The \TeX\ text would look like this in your \.{WEB} file:
  330. $$\.{The characters are placed into |buffer|, which is a |packed
  331. array [1..n] of char|.}$$
  332. And \.{WEAVE} translates this into something you are glad you didn't have
  333. to type:
  334. $$\lpile{\.{The characters are placed into \\\\\{buffer\},}\cr
  335.   \.{which is a \\\&\{packed\}{ }\\\&\{array\}{ }\$
  336.     [1\\to\\|n]\${ }\\\&\{of\}{ }\\\\\{char\}.}\cr}$$
  337. Incidentally, the cross-reference index that \.{WEAVE} would make, in
  338. the presence of a comment like this, would include
  339. the current module number as one of the index entries for \\{buffer}
  340. \vadjust{\eject}% page break inserted Dec 88
  341. and \\{char}, even though \\{buffer} and \\{char}
  342. might not appear in the \PASCAL\ part of
  343. this module. Thus, the index covers references to identifiers in
  344. the explanatory comments as well as in the program itself; you will
  345. soon learn to appreciate this feature. However, the identifiers
  346. \&{packed} and \&{array} and \|n\ and \&{of\/} would not be indexed,
  347. because \.{WEAVE} does not make index entries for reserved words or
  348. single-letter identifiers. Such identifiers are felt to be so ubiquitous
  349. that it would be pointless to mention every place where they occur.
  350. Speaking of identifiers, the author of \.{WEB} thinks that
  351. \\{IdentifiersSeveralWordsLong} look terribly ugly when they mix
  352. uppercase and lowercase letters. He recommends that
  353. \\{identifiers\_several\_words\_long} be written with underline characters
  354. to get a much better effect. The actual identifiers sent to the \PASCAL\
  355. compiler by \.{TANGLE} will have such underlines removed, and \.{TANGLE}
  356. will check to make sure that two different identifiers do not become
  357. identical when this happens. (In fact, \.{TANGLE} even checks that
  358. the first seven characters of identifiers are unique, when lowercase
  359. letters have been converted to uppercase; the number seven in this
  360. constraint is more strict than \PASCAL's eight, and it can
  361. be changed if desired.) The \.{WEAVE} processor will properly
  362. alphabetize identifiers that have embedded underlines
  363. when it makes the index.
  364. Although a module begins with \TeX\ text and ends with \PASCAL\ text, we
  365. have noted that the dividing line isn't sharp, since \PASCAL\ text can be
  366. included in \TeX\ text if it is enclosed in `\pb'.  Conversely, \TeX\ text
  367. also appears frequently within \PASCAL\ text, because everything in
  368. comments (i.e., between left and right braces) is treated as \TeX\ text.
  369. Furthermore, a module name consists of \TeX\ text; thus, a \.{WEB} file
  370. typically involves constructions like `\.{if} \.x \.= \.0 \.{then}
  371. \.{@<Empty} \.{the} \.{|buffer|} \.{array@>}' where we go back and forth
  372. between \PASCAL\ and \TeX\ conventions in a natural way.
  373. \section Macros.
  374. A \.{WEB} programmer can define three kinds of macros to make the programs
  375. shorter and more readable:
  376. \yskip\hang`\.{@d} \\{identifier} \.= \\{constant}' defines a {\sl numeric\/}
  377. macro, allowing \.{TANGLE} to do rudimentary arithmetic.
  378. \yskip\hang`\.{@d} \\{identifier} \.{==} \PASCAL\ text' defines a {\sl
  379. simple\/} macro, where the identifier will be replaced by the \PASCAL\ text
  380. when \.{TANGLE} produces its output.
  381. \yskip\hang`\.{@d} \\{identifier}\.{(\#) ==} \PASCAL\ text' defines a
  382. {\sl parametric\/} macro, where the identifier will be replaced by the \PASCAL\
  383. text and where occurrences of \.{\#} in that \PASCAL\ text will be
  384. replaced by an argument.
  385. \yskip\noindent In all three cases, the identifier must have length greater
  386. than one; it must not be a single letter.
  387. Numeric macros are subject to the following restrictions:\quad
  388. (1)~The identifier must
  389. be making its first appearance in the \.{WEB} file;
  390. a numeric macro must be defined before it is used.\quad
  391. (2)~The right-hand side of the numeric definition must be made entirely from
  392. integer constants, numeric macros, preprocessed strings (see below), and
  393. plus~signs or minus signs.  No other operations or symbols are allowed,
  394. not even parentheses, except that \PASCAL-like comments (enclosed in
  395. braces) can appear. Indeed, comments are recommended, since it is usually
  396. wise to give a brief explanation of the significance of each identifier as
  397. it is defined.\quad
  398. (3)~The numeric value must be less than $2^{15}=32768$ in absolute value.
  399. (For larger values, you can use `\.{==}' in place of~`\.=', thus making use
  400. of a simple macro instead of a numeric one. Note, however, that simple
  401. macros sometimes have a different effect. For example, consider the three
  402. definitions `\.{@d n1=2 @d n2=2+n1 @d n3==2+n1}'; then `\.{x-n2}' will
  403. expand into `\.{x-4}', while `\.{x-n3}' will expand into `\.{x-2+2}' which
  404. is quite different! It is wise to include parentheses in non-numeric
  405. macros, e.g., `\.{@d n3==(2+n1)}', to avoid such errors.)
  406. When constants are connected by plus signs or minus
  407. signs in a \PASCAL\ program, \.{TANGLE} does the arithmetic before putting
  408. the constant into the output file. Therefore it is permissible to say, for
  409. example, `\&{array} $[0\,.\,.\,\\{size}-1]$' if \\{size} has been declared
  410. as a macro; note that \PASCAL\ doesn't allow this kind of compile-time
  411. arithmetic if \\{size} is a \&{constant} quantity in the program. Another
  412. use of \.{TANGLE}'s arithmetic is to make \&{case} statement labels such
  413. as `$\\{flag}+1$' legitimate. Of course, it is improper to change \.{2+2}
  414. into \.4 without looking at the surrounding context; many counterexamples
  415. exist, such as the phrases `\.{-2+2}', `\.{x/2+2}', and `\.{2+2E5}'.  The
  416. program for \.{TANGLE}, in the appendix, gives precise details about this
  417. conversion, which \.{TANGLE} does only when it is safe.
  418. The right-hand sides of simple and parametric macros
  419. are required to have balanced parentheses, and the \PASCAL\ texts of
  420. modules must have balanced parentheses too. Therefore when the argument
  421. to a para\-metric macro appears in parentheses, both parentheses
  422. will belong to the same \PASCAL\ text.
  423. The appendices to this report contain hundreds of typical examples of the
  424. usefulness of \.{WEB} macros, so it is not necessary to dwell on the
  425. subject here. However, the reader should know that \.{WEB}'s apparently
  426. primitive macro capabilities can actually do a lot of rather surprising
  427. things. Here is a construction that sheds further light on what is
  428. possible: After making the definitions
  429. $$\catcode`\#=12
  430. \lpile{\.{@d two\_cases(#)==case j of 1:#(1); 2:#(2); end}\cr
  431. \.{@d reset\_file(#)==reset(input\_file@\&#)}\cr}$$
  432. one can write `\.{two\_cases(reset\_file)}' and the resulting \PASCAL\
  433. output will be
  434. $$\.{case j of 1:reset(input\_file1); 2:reset(input\_file2); end}$$
  435. (but in uppercase letters and with \.\_'s removed).
  436. The `\.{@\&}' operation used here joins together two adjacent tokens
  437. into a single token, as explained later; otherwise the \PASCAL\ file would
  438. contain a space between \.{input\_file} and the digit that followed it.
  439. This trick can be used to provide the effect of an array of files, if you
  440. are unfortunate enough to have a \PASCAL\ compiler that doesn't allow such
  441. arrays.  Incidentally, the cross-reference index made by \.{WEAVE} from
  442. this example would contain the identifier \\{input\_file} but it would not
  443. contain \\{input\_file1} or \\{input\_file2}. Furthermore, \.{TANGLE}
  444. would not catch the error that \.{INPUTFILE1} and \.{INPUTFILE2} both
  445. begin with the same nine letters; one should be more careful when using
  446. `\.{@\&}'! But such aspects of the construction in this trick are
  447. peripheral to our main point, which is that a parametric macro name without
  448. arguments can be used as an argument to another parametric macro.
  449. Although \.{WEB}'s macros are allowed to have at most one parameter, the
  450. following example shows that this is not as much of a restriction as it
  451. may seem at first. Let \\{amac} and \\{bmac} be any parametric macros, and
  452. suppose that we want to get the effect of
  453. $$\catcode`\#=12
  454. \.{@d cmac(#1,#2) == amac(#1) bmac(#2)}$$
  455. which \.{WEB} doesn't permit. The solution is to make the definitions
  456. $$\catcode`\#=12
  457. \lpile{\.{@d cmac(#) == amac(#) dmac}\cr
  458. \.{@d dmac(#) == bmac(#)}\cr}$$
  459. and then to say `\.{cmac(x)(y)}'.
  460. There is one restriction in the generality of \.{WEB}'s parametric
  461. macros, however: the argument to a para\-metric macro must not come from
  462. the expansion of a macro that has not already been ``started.'' For
  463. example, here is one of the things \.{WEB} cannot handle:
  464. $$\catcode`\#=12
  465. \lpile{\.{@d arg == (p)}\cr
  466. \.{@d identity(#) == #}\cr
  467. \.{@p identity arg}\cr}$$
  468. In this case \.{TANGLE} will complain that the \.{identity} macro is not
  469. followed by an argument in parentheses.
  470. The \.{WEB} language has another feature that is somewhat similar to a
  471. numeric macro. A {\sl preprocessed string\/} is a string that is like
  472. a \PASCAL\ string but delimited by double-quote marks (\.") instead of
  473. single-quotes. Double-quote marks inside of such strings are indicated by
  474. giving two double-quotes in a row. If a preprocessed string is
  475. of length one (e.g., \.{"A"} or \.{""""}), it will be treated by \.{TANGLE}
  476. as equivalent to the corresponding ASCII-code integer (e.g., \.{65} or
  477. \.{34}). And if a preprocessed string is not of length one, it will be
  478. converted into an integer equal to 128 or more. A {\sl string pool\/}
  479. containing all such strings will be written out by the \.{TANGLE}
  480. processor; this string pool file consists of string 128, then string 129,
  481. etc., where each string is followed by an end-of-line and prefixed by two
  482. decimal digits that define its length.  Thus, for example, the empty string
  483. \.{""} would be represented in the string pool file by a line containing
  484. the two characters `\.{00}', while the string \.{"""String"""} would be
  485. represented by `\.{08"String"}'.  A given string appears at most once in
  486. the string pool; the use of such a pool makes it easier to cope with
  487. \PASCAL's restrictions on string manipulation. The string pool ends with
  488. `\.{*nnnnnnnnn}', where \.{nnnnnnnnn} is a decimal number
  489. called the {\sl string pool check sum}. If any string changes, the check
  490. sum almost surely changes too; thus, the `\.{@\$}' feature
  491. described below makes it possible for a program to assure itself that it
  492. is reading its own string pool.
  493. Here is a simple example that combines numeric macros with preprocessed
  494. strings of length one:
  495. $$\lpile{\.{@d upper\_case\_Y = "Y"}\cr
  496. \.{@d case\_difference = -"y"+upper\_case\_Y}\cr}$$
  497. The result is to define
  498. $\\{upper\_case\_Y}=89$, $\\{case\_difference}=-32$.
  499. \section Control codes.
  500. We have seen several magic uses of `\.{@}' signs in \.{WEB} files, and it
  501. is time to make a systematic study of
  502. these special features. A \.{WEB} {\sl control code\/}
  503. is a two-character combination of which the first is `\.@'.
  504. Here is a complete list of the legal control codes. The letters $L$, $T$,
  505. $P$, $M$, $C$, and/or $S$ following each code indicate whether or not that
  506. code is allowable in limbo, in \TeX\ text, in \PASCAL\ text, in module
  507. names, in comments, and/or in strings.  A bar over such a letter means
  508. that the control code terminates the present part of the \.{WEB} file; for
  509. example, $\overline L$ means that this control code ends the limbo material
  510. before the first module.
  511. \def\@#1[#2] {\yskip\hangindent 2em\noindent\.{@#1\unskip
  512.   \spacefactor1000{ }}$[#2]$\quad}
  513. \def\oP{\overline P}
  514. \def\oT{\overline T}
  515. \@@ [C,L,M,P,S,T] A double \.@ denotes the single character `\.@'. This is
  516. the only control code that is legal in limbo, in comments, and in strings.
  517. \@\ [\overline L,\oP,\oT] This denotes the beginning of a new
  518. (unstarred) module. A tab mark or end-of-line (carriage return)
  519. is equivalent to a space when it follows an \.@ sign.
  520. \@* [\overline L,\oP,\oT] This denotes the beginning of a new starred
  521. module, i.e., a module that begins a new major group. The title of the new
  522. group should appear after the \.{@*}, followed by a period. As explained
  523. above, \TeX\ control sequences should be avoided in such titles unless
  524. they are quite simple. When \.{WEAVE} and \.{TANGLE} read a \.{@*}, they
  525. print an asterisk followed by the current module number, so that the user
  526. can see some indication of progress. The very first module should be starred.
  527. \@d [\oP,\oT] Macro definitions begin with \.{@d} (or \.{@D}), followed by
  528. the \PASCAL\ text for one of the three kinds of macros, as explained
  529. earlier.
  530. \@f [\oP,\oT] Format definitions begin with \.{@f} (or \.{@F}); they cause
  531. \.{WEAVE} to treat identifiers in a special way when they appear in
  532. \PASCAL\ text. The general form of a format definition is `\.{@f} \|l \.{==}
  533. \|r', followed by an optional comment enclosed in braces, where \|l and \|r
  534. are identifiers; \.{WEAVE} will subsequently treat identifier \|l as it
  535. currently treats \|r. This feature allows a \.{WEB} programmer to invent
  536. new reserved words and/or to unreserve some of \PASCAL's reserved
  537. identifiers. The definition part of each module consists of any number of
  538. macro definitions (beginning with \.{@d}) and format definitions (beginning
  539. with \.{@f}), intermixed in any order.
  540. \@p [\oP,\oT] The \PASCAL\ part of an unnamed module begins with \.{@p}
  541. (or \.{@P}). This causes \.{TANGLE} to append the following \PASCAL\ code
  542. to the initial program text $T_0$ as explained above. The \.{WEAVE}
  543. processor does not cause a `\.{@p}' to appear explicitly in the \TeX\
  544. output, so if you are creating a \.{WEB} file based on a \TeX-printed
  545. \.{WEB} documentation you have to remember to insert \.{@p} in the
  546. appropriate places of the unnamed modules.
  547. \@< [P,\oT] A module name begins with \.{@<} followed by \TeX\ text followed
  548. by \.{@>}; the \TeX\ text should not contain any \.{WEB} control sequences
  549. except \.{@@}, unless these control sequences appear in \PASCAL\ text that
  550. is delimited by \pb. The module name may be abbreviated, after its first
  551. appearance in a \.{WEB} file, by giving any unique prefix followed by \.{...},
  552. where the three dots immediately precede the closing \.{@>}. No module name
  553. should be a prefix of another. Module names may not appear in \PASCAL\
  554. text that is enclosed in \pb, nor may they appear in the definition part
  555. of a module (since the appearance of a module name ends the definition
  556. part and begins the \PASCAL\ part).
  557. \@\' [P,T] This denotes an octal constant, to be formed from the
  558. succeeding digits. For example, if the \.{WEB} file contains `\.{@\'100}',
  559. the \.{TANGLE} processor will treat this an equivalent to `\.{64}';
  560. the constant will be formatted as ``\O{100}'' in the \TeX\ output
  561. produced via \.{WEAVE}. You should use octal notation only for positive
  562. constants; don't try to get, e.g., $-1$ by saying `\.{@\'777777777777}'.
  563. \@" [P,T] A hexadecimal constant; `\.{@"D0D0}' tangles to \.{53456} and
  564. weaves to `\H{D0D0}'.
  565. \@\$ [P] This denotes the string pool check sum.
  566. \@\{ [P] The beginning of a ``meta comment,'' i.e., a comment
  567. that is supposed to appear in the \PASCAL\ code, is indicated by
  568. \.{@\{} in the \.{WEB} file. Such delimiters can be used as
  569. isolated symbols in macros or modules, but they should be properly nested
  570. in the final \PASCAL\ program. The \.{TANGLE} processor will convert
  571. `\.{@\{}' into `\.\{' in the \PASCAL\ output file, unless
  572. the output is already part of a meta-comment; in the latter case
  573. `\.{@\{}' is converted into `\.[', since \PASCAL\ does not allow
  574. nested comments. Incidentally, module numbers are automatically inserted
  575. as meta-comments into the \PASCAL\ program, in order to help correlate the
  576. outputs of \.{WEAVE} and \.{TANGLE} (see Appendix~C\null). Meta-comments
  577. can be used to put conditional text into a \PASCAL\ program; this helps to
  578. overcome one of the limitations of \.{WEB}, since the simple macro
  579. processing routines of \.{TANGLE} do not include the dynamic evaluation of
  580. boolean expressions.
  581. \@\} [P] The end of a ``meta comment'' is indicated by `\.{@\}}'; this is
  582. converted either into `\.\}' or `\.{]}' in the \PASCAL\ output, according
  583. to the conventions explained for \.{@\{} above.
  584. \@\& [P] The \.{@\&} operation causes whatever is on its left to be
  585. adjacent to whatever is on its right, in the \PASCAL\ output. No spaces or
  586. line breaks will separate these two items. However, the thing on the left
  587. should not be a semicolon, since a line break might occur after a semicolon.
  588. \@\^ [P,T] The ``control text'' that follows, up to the next
  589. `\.{@>}', will be entered into the index together with the identifiers of
  590. the \PASCAL\ program; this text will appear in roman type. For example, to
  591. put the phrase ``system dependencies'' into the index, you can type
  592. `\.{@\^system dependencies@>}' in each module
  593. that you want to index as system dependent. A control text, like a string,
  594. must end on the same line of the \.{WEB} file as it began.  Furthermore,
  595. no \.{WEB} control sequences are allowed in a control text, not even
  596. \.{@@}. (If you need an \.{@} sign you can get around this restriction by
  597. typing `\.{\\AT!}'.)
  598. \@. [P,T] The ``control text'' that follows will be entered into the index
  599. in \.{typewriter} \.{type}; see the rules for `\.{@\^}', which is analogous.
  600. \@: [P,T] The ``control text'' that follows will be entered into the index
  601. in a format controlled by the \TeX\ macro `\.{\\9}', which the user
  602. should define as desired; see the rules for `\.{@\^}', which is analogous.
  603. \@t [P] The ``control text'' that follows, up to the next `\.{@>}', will
  604. be put into a \TeX\ \.{\\hbox} and formatted along with the neighboring
  605. \PASCAL\ program. This text is ignored by \.{TANGLE}, but it can be used
  606. for various purposes within \.{WEAVE}. For example, you can make comments
  607. that mix \PASCAL\ and classical mathematics, as in `$\\{size}<2^{15}$', by
  608. typing `\.{|size < @t\$2\^\{15\}\$@>|}'.  A control text must end on the
  609. same line of the \.{WEB} file as it began, and it may not contain any
  610. \.{WEB} control codes.
  611. \@= [P] The ``control text'' that follows, up to the next `\.{@>}', will
  612. be passed verbatim to the \PASCAL\ program.
  613. \@\\ [P] Force end-of-line here in the \PASCAL\ program file.
  614. \@! [P,T] The module number in an index entry will be underlined if `\.{@!}'
  615. immediately precedes the identifier or control text being indexed. This
  616. convention is used to distinguish the modules where an identifier is
  617. defined, or where it is explained in some special way, from the modules
  618. where it is used. A~reserved word or an identifier of length one will not
  619. be indexed except for underlined entries. An `\.{@!}' is implicitly inserted
  620. by \.{WEAVE} just after the reserved words \&{function}, \&{procedure},
  621. \&{program}, and \&{var}, and just after \.{@d} and \.{@f}. But you should
  622. insert your own `\.{@!}' before the definitions of types, constants,
  623. variables, parameters, and components of records and enumerated types that
  624. are not covered by this implicit convention, if you want to improve the
  625. quality of the index that you get.
  626. \@? [P,T] This cancels an implicit (or explicit) `\.{@!}', so that the next
  627. index entry will not be underlined.
  628. \@, [P] This control code inserts a thin space in \.{WEAVE}'s output; it is
  629. ignored by \.{TANGLE}. Sometimes you need this extra space if you are using
  630. macros in an unusual way, e.g., if two identifiers are adjacent.
  631. \@/ [P] This control code causes a line break to occur within a \PASCAL\
  632. program formatted by \.{WEAVE}; it is ignored by \.{TANGLE}. Line breaks
  633. are chosen automatically by \TeX\ according to a scheme that works 99\%\
  634. of the time, but sometimes you will prefer to force a line break so that
  635. the program is segmented according to logical rather than visual criteria.
  636. Caution: `\.{@/}' should be used only after statements or clauses, not in
  637. the middle of an expression; use \.{@|} in the middle of expressions, in
  638. order to keep \.{WEAVE}'s parser happy.
  639. \@| [P] This control code specifies an optional line break in the midst of
  640. an expression. For example, if you have a long condition between \&{if} and
  641. \&{then}, or a long expression on the right-hand side of an assignment
  642. statement, you can use `\.{@|}' to specify breakpoints more logical than
  643. the ones that \TeX\ might choose on visual grounds.
  644. \@\# [P] This control code forces a line break, like \.{@/} does,
  645. and it also causes a little extra white space to appear between the lines at
  646. this break. You might use it, for example, between procedure definitions or
  647. between groups of macro definitions that are logically separate but within
  648. the same module.
  649. \@+ [P] This control code cancels a line break that might otherwise be
  650. inserted by \.{WEAVE}, e.g., before the word `\&{else}', if you want to
  651. put a short if-then-else construction on a single line. It is ignored by
  652. \.{TANGLE}.
  653. \@; [P] This control code is treated like a semicolon, for formatting
  654. purposes, except that it is invisible. You can use it, for example, after
  655. a module name when the \PASCAL\ text represented by that module name ends
  656. with a semicolon.
  657. \yskip\noindent
  658. The last six control codes (namely `\.{@,}', `\.{@/}', `\.{@|}',
  659. `\.{@\#}', `\.{@+}', and `\.{@;}') have no effect on the \PASCAL\
  660. program output by \.{TANGLE}; they merely help to improve the readability
  661. of the \TeX-formatted \PASCAL\ that is output by \.{WEAVE}, in unusual
  662. circumstances. \.{WEAVE}'s built-in formatting method is fairly good, but
  663. it is incapable of handling all possible cases, because it must deal with
  664. fragments of text involving macros and module names; these fragments do
  665. not necessarily obey \PASCAL's syntax. Although \.{WEB} allows you to
  666. override the automatic formatting, your best strategy is not to worry
  667. about such things until you have seen what \.{WEAVE} produces automatically,
  668. since you will probably need to make only a few corrections when you are
  669. touching up your documentation.
  670. Because of the rules by which every module is broken into three parts,
  671. the control codes `\.{@d}', `\.{@f}', and `\.{@p}' are not allowed to occur
  672. once the \PASCAL\ part of a module has begun.
  673. \section Additional features and caveats.
  674. 1. The character pairs `\.{(*}', `\.{*)}', `\.{(.}', and `\.{.)}' are
  675. converted automatically in \PASCAL\ text as though they were
  676. `\.{@\{}', `\.{@\}}', `\.[', and `\.]', respectively, except
  677. of course in strings. Furthermore in certain installations of \.{WEB} that
  678. {\def\\#1#2{`{\tentex\char'#1#2}'}%
  679. have an extended character set, the characters \\32, \\34, \\35, \\30,
  680. \\36, \\04, \\37, \\05, and \\06}
  681. can be used as abbreviations for
  682. `\.{<>}', `\.{<=}', `\.{>=}', `\.{:=}', `\.{==}', `\.{and}', `\.{or}',
  683. `\.{not}', and `\.{in}', respectively. However, the latter abbreviations
  684. are not used in the standard versions of \.{WEAVE.WEB} and \.{TANGLE.WEB}
  685. that are distributed to people who are installing \.{WEB} on other
  686. computers, and the programs are designed to produce only standard ASCII
  687. characters as output if the input consists entirely of ASCII characters.
  688. 2. If you have an extended character set, all of the characters listed
  689. in Appendix C of {\sl The \TeX book\/} can be used in strings. But you should
  690. stick to standard ASCII characters if you want to write programs that will
  691. be useful to the all the poor souls out there who don't have extended
  692. character sets.
  693. 3. The \TeX\ file output by \.{WEAVE} is broken into lines having at most
  694. 80 characters each. The algorithm that does this line breaking is unaware
  695. of \TeX's convention about comments following `\.\%' signs on a line. When
  696. \TeX\ text is being copied, the existing line breaks are copied as well,
  697. so there is no problem with `\.\%' signs unless the original \.{WEB} file
  698. contains a line more than eighty characters long or a line with \PASCAL\
  699. text in \pb\ that expands to more than eighty characters long. Such lines
  700. should not have `\.\%' signs.
  701. 4. \PASCAL\ text is translated by a ``bottom up'' procedure that
  702. identifies each token as a ``part of speech'' and combines parts of speech
  703. into larger and larger phrases as much as possible according to a special
  704. grammar that is explained in the documentation of \.{WEAVE}. It is easy to
  705. learn the translation scheme for simple constructions like single
  706. identifiers and short expressions, just by looking at a few examples of
  707. what \.{WEAVE} does, but the general mechanism is somewhat complex because
  708. it must handle much more than \PASCAL\ itself. Furthermore the output
  709. contains embedded codes that cause \TeX\ to indent and break lines as
  710. necessary, depending on the fonts used and the desired page width. For
  711. best results it is wise to adhere to the following restrictions:
  712. \yskip\itemitem{a)}Comments in \PASCAL\ text should appear only after
  713. statements or clauses; i.e., after semicolons, after reserved words like
  714. \&{then} and \&{do}, or before reserved words like \&{end} and \&{else}.
  715. Otherwise \.{WEAVE}'s parsing method may well get mixed up.
  716. \itemitem{b)}Don't enclose long \PASCAL\ texts in \pb, since the
  717. indentation and line breaking codes are omitted when the \pb\ text is
  718. translated from \PASCAL\ to \TeX. Stick to simple expressions or
  719. statements.
  720. \yskip
  721. 5. Comments and module names are not permitted in \pb\ text. After a `\.|'
  722. signals the change from \TeX\ text to \PASCAL\ text, the next `\.|' that is
  723. not part of a string or control text ends the \PASCAL\ text.
  724. 6. A comment must have properly nested occurrences of left and right
  725. braces, otherwise \.{WEAVE} and \.{TANGLE} will not know where the comment
  726. ends. However, the character pairs `\.{\\\{}' and `\.{\\\}}' do not count
  727. as left and right braces in comments, and the character pair `\.{\\|}'
  728. does not count as a delimiter that begins \PASCAL\ text. (The actual rule
  729. is that a character after `\.\\' is ignored; hence in `\.{\\\\\{}' the
  730. left brace {\sl does\/} count.) At present, \.{TANGLE} and \.{WEAVE} treat
  731. comments in slightly different ways, and it is necessary to satisfy both
  732. conventions: \.{TANGLE} ignores `\.|' characters entirely, while \.{WEAVE}
  733. uses them to switch between \TeX\ text and \PASCAL\ text. Therefore, a
  734. comment that includes a brace in a string in \pb---e.g., `\.{\{{ }look at
  735. this |"\{"| \}}'---will be handled correctly by \.{WEAVE}, but \.{TANGLE}
  736. will think there is an unmatched left brace. In order to satisfy both
  737. processors, one can write `\.{\{{ }look at this \\leftbrace\\{ }\}}', after
  738. setting up`\.{\\def\\leftbrace\{|"\{"|\}}'.
  739. 7. Reserved words of \PASCAL\ must appear entirely in lowercase letters
  740. in the \.{WEB} file; otherwise their special nature will not be recognized
  741. by \.{WEAVE}. You could, for example, have a macro named \\{END} and it
  742. would not be confused with \PASCAL's \&{end}.
  743. However, you may not want to capitalize macro names just to distinguish them
  744. from other identifiers.  Here is a way to unreserve \PASCAL's reserved word
  745. `\&{type}' and to substitute another word `\&{mtype}' in the \.{WEB} file.
  746. $$\vbox{\halign{\tt #\hfil\cr
  747. @d type(\char'43) == mem[\char'43].t\cr
  748. @d mtype == t \char'100\char'46{} y \char'100\char'46{} p
  749.   \char'100\char'46{} e\cr
  750. @f mtype == type\cr
  751. @f type == true\cr}}$$
  752. In the output of \.{TANGLE}, the macro \.{mtype} now produces `\.{TYPE}'
  753. and the macro \.{type(x)} now produces `\.{MEM[X].T}'. In the output of
  754. \.{WEAVE}, these same inputs produce \&{mtype} and \\{type}(\|x),
  755. respectively.
  756. 8. The \.{@f} feature allows you to define one identifier to act like
  757. another, and these format definitions are carried out sequentially, as the
  758. example above indicates. However, a given identifier has only one printed format
  759. throughout the entire document (and this format will even be used before
  760. the \.{@f} that defines it). The reason is that \.{WEAVE} operates in two
  761. passes; it processes \.{@f}'s and cross-references on the first pass and
  762. does the output on the second.
  763. 9. You may want some \.{@f} formatting that doesn't correspond to any
  764. existing reserved word. In that case, \.{WEAVE} could be extended in a
  765. fairly obvious way to include new ``reserved words'' in its vocabulary.
  766. The identifier `\&{xclause}' has in fact been included already as a
  767. reserved word, so that it can be used to format the `\&{loop}' macro,
  768. where `\&{loop}' is defined to be equivalent to `\&{while \\{true} do}'.
  769. 10. Sometimes it is desirable to insert spacing into \PASCAL\ code that is
  770. more general than the thin space provided by `\.{@,}'. The \.{@t} feature
  771. can be used for this purpose; e.g., `\.{@t\\hskip 1in@>}' will
  772. leave one inch of blank space. Furthermore, `\.{@t\\4@>}' can be
  773. used to backspace by one unit of indentation, since the control sequence
  774. \.{\\4} is defined in \.{webmac} to be such a backspace. (This
  775. control sequence is used, for example, at the beginning of lines that
  776. contain labeled statements, so that the label will stick out a little at
  777. the left.)
  778. 11. \.{WEAVE} and \.{TANGLE} are designed to work with two input files,
  779. called \\{web\_file} and \\{change\_file}, where \\{change\_file} contains
  780. data that overrides selected portions of \\{web\_file}. The resulting merged
  781. text is actually what has been called the \.{WEB} file elsewhere in this
  782. report.
  783. Here's how it works: The change file consists of zero or more ``changes,''
  784. where a change has the form `\.{@x}$\langle$old lines$\rangle$\.{@y}$\langle$%
  785. new lines$\rangle$\.{@z}'. The special control codes \.{@x}, \.{@y}, \.{@z},
  786. which are allowed only in change files, must appear at the beginning of a line;
  787. the remainder of such a line is ignored.
  788. The $\langle$old lines$\rangle$ represent material that exactly matches
  789. consecutive lines of the \\{web\_file}; the $\langle$new lines$\rangle$
  790. represent zero or more lines that are supposed to replace the old. Whenever
  791. the first ``old line'' of a change is found to match a line in the
  792. \\{web\_file}, all the other lines in that change must match too.
  793. Between changes, before the first change, and after the last change,
  794. the change file can have any number of lines that do not begin with
  795. `\.{@x}', `\.{@y}', or~`\.{@z}'. Such lines are bypassed and not used for
  796. matching purposes.
  797. This dual-input feature is useful when working with a master \.{WEB} file
  798. that has been received from elsewhere (e.g., \.{TANGLE.WEB} or
  799. \.{WEAVE.WEB} or \.{TEX.WEB}), when changes are desirable to customize the
  800. program for your local computer system. You will be able to debug your
  801. system-dependent changes without clobbering the master web file; and once
  802. your changes are working, you will be able to incorporate them readily
  803. into new releases of the master web file that you might receive from time
  804. to time.
  805. \section Appendices.
  806. The basic ideas of \.{WEB} can be understood most easily by looking at
  807. examples of ``real'' programs. Appendix~A shows the \.{WEB} input that
  808. generated modules 55--59 of the \.{WEAVE} program; Appendix~B shows the
  809. corresponding \TeX\ code output by \.{WEAVE}; and Appendix~C shows excerpts
  810. from the corresponding \PASCAL\ code output by \.{TANGLE}.
  811. The complete webs for \.{WEAVE} and \.{TANGLE} appear as the bulk of this
  812. report, in Appendices D and~E. The reader should first compare Appendix~A
  813. to the corresponding portion of Appendix~D; then the same material should
  814. be compared to Appendices B and~C. Finally, if time permits, the reader may
  815. enjoy studying the complete programs in Appendices D and~E, since \.{WEAVE}
  816. and \.{TANGLE} contain several interesting aspects, and since an attempt
  817. has been made in these appendices to evolve a style of programming that
  818. makes good use of the \.{WEB} language.
  819. Finally, Appendix F is the `\.{webmac}' file that sets \TeX\ up to accept
  820. the output of \.{WEAVE}; Appendix~G discusses how to use some of its macros
  821. to vary the output formats; and Appendix~H discusses what needs to be done
  822. when \.{WEAVE} and \.{TANGLE} are installed in a new operating environment.
  823. \section Performance statistics.
  824. The programs in Appendices D and E will optionally keep statistics on
  825. how much memory they require. Here is what they printed out when
  826. processing themselves:
  827. \def\pstat#1#2#3
  828. #4{\yskip\noindent\.{#1} applied to \.{#2} (cpu time #3 sec)\par
  829. \halign{\quad\tt##\hfil\cr#4}}
  830. \pstat{TANGLE}{TANGLE}{15}
  831. {Memory usage statistics:\cr
  832. 456 names, 215 replacement texts;\cr
  833. 3396+3361 bytes, 6685+7329+5805 tokens.\cr}
  834. \pstat{TANGLE}{WEAVE}{30}
  835. {Memory usage statistics:\cr
  836. 692 names, 339 replacement texts;\cr
  837. 4576+4294 bytes, 10184+9875+9150 tokens.\cr}
  838. \pstat{WEAVE}{TANGLE}{45}
  839. {Memory usage statistics: 478 names, 2045 cross references, 4159+3729 bytes;\cr
  840. parsing required 684 scraps, 1300 texts, 3766 tokens, 119 levels;\cr
  841. sorting required 34 levels.\cr}
  842. \pstat{WEAVE}{WEAVE}{65}
  843. {Memory usage statistics: 737 names, 3306 cross references, 4896+4962 bytes;\cr
  844. parsing required 684 scraps, 1300 texts, 3766 tokens, 119 levels;\cr
  845. sorting required 73 levels.\cr}
  846. \yskip\noindent The cpu time for \PASCAL\ to process \.{TANGLE.PAS} was
  847. approximately 13 seconds, and \.{WEAVE.PAS} took approximately 26 seconds;
  848. thus the tangling time was slightly more than the compiling time.  The cpu
  849. time for \TeX\ to process \.{TANGLE.TEX} was approximately 500 seconds,
  850. and \.{WEAVE.TEX} took approximately 750 seconds (i.e., about 7
  851. seconds per printed page, where these pages are substantially larger than
  852. the pages in a normal book). All cpu times quoted are for a DECsystem-10.
  853. \def\K{{\mc K}}
  854. The file \.{TANGLE.WEB} is about 125\K\ characters long; \.{TANGLE}
  855. reduces it to a file \.{TANGLE.PAS} whose size is about 42\K\ characters,
  856. while \.{WEAVE} expands it to a file \.{TANGLE.TEX} of about 185\K\null.
  857. The corresponding file sizes for \.{WEAVE.WEB}, \.{WEAVE.PAS}, and
  858. \.{WEAVE.TEX} are 180\K, 89\K, and 265\K.
  859. The much larger file \.{TEX.WEB} led to the following numbers:
  860. \pstat{TANGLE}{TEX}{110}
  861. {Memory usage statistics:\cr
  862. 3750 names, 1768 replacement texts;\cr
  863. 41895+41053 bytes, 42378+45074+41091 tokens.\cr}
  864. \pstat{WEAVE}{TEX}{270}
  865. {Memory usage statistics: 3412 names, 19699 cross references,
  866.   37900+40232 bytes;\cr
  867. parsing required 685 scraps, 1303 texts, 3784 tokens, 104 levels;\cr
  868. sorting required 52 levels.\cr}
  869. \yskip\noindent
  870. \PASCAL\ did \.{TEX.PAS} in about 75 seconds; \TeX\ did \.{TEX.TEX}
  871. in about 3600.
  872. % Here is a quotation that could not really be omitted
  873. \vfill
  874. {\baselineskip9pt
  875. \halign to\hsize{\hfil\quoteit#\tabskip 0pt plus 100pt&
  876.   \hfil\quoteit#\tabskip 0pt\cr
  877. O, what a tangled web we weave&
  878.   O, what a tangled WEB we weave\cr
  879. When first we practise to deceive!&
  880.   When \TeX\ we practise to conceive!\cr
  881. \noalign{\vskip 2pt}
  882. \quoterm ---SIR WALTER SCOTT, {\quoteit Marmion} 6:17 (1808)&
  883.   \quoterm ---RICHARD PALAIS (1982)\cr
  884. \eject
  885. \def\runninghead{APPENDIX A --- {\tentt WEB} FILE FORMAT}
  886. \section Appendix A.
  887. This excerpt from \.{WEAVE.WEB} produced modules 55--59 in Appendix~D.
  888. Note that some of the lines are indented to show the program structure.
  889. The indentation is ignored by \.{WEAVE} and \.{TANGLE}, but users find
  890. that \.{WEB} files are quite readable if they have some such indentation.
  891. \vskip 6pt
  892. \begingroup \def\tt{\eighttt} \baselineskip9pt
  893. % Note to myself: I had to remove SAIL characters from the file here!
  894. % Also tabs replaced by double-space. The changes were made in WEAVE source.
  895. \verbatim
  896. @* Searching for identifiers.
  897. The hash table described above is updated by the |id_lookup| procedure,
  898. which finds a given identifier and returns a pointer to its index in
  899. |byte_start|. The identifier is supposed to match character by character
  900. and it is also supposed to have a given |ilk| code; the same name may be
  901. present more than once if it is supposed to appear in the index with
  902. different typesetting conventions.
  903. If the identifier was not already present, it is inserted into the table.
  904. Because of the way \.{WEAVE}'s scanning mechanism works, it is most convenient
  905. to let |id_lookup| search for an identifier that is present in the |buffer|
  906. array. Two other global variables specify its position in the buffer: the
  907. first character is |buffer[id_first]|, and the last is |buffer[id_loc-1]|.
  908. @<Glob...@>=
  909. @!id_first:0..long_buf_size; {where the current identifier begins in the buffer}
  910. @!id_loc:0..long_buf_size; {just after the current identifier in the buffer}
  911. @!hash:array [0..hash_size] of sixteen_bits; {heads of hash lists}
  912. @ Initially all the hash lists are empty.
  913. @<Local variables for init...@>=
  914. @!h:0..hash_size; {index into hash-head array}
  915. @ @<Set init...@>=
  916. for h:=0 to hash_size-1 do hash[h]:=0;
  917. @ Here now is the main procedure for finding identifiers (and index
  918. entries).  The parameter |t| is set to the desired |ilk| code. The
  919. identifier must either have |ilk=t|, or we must have
  920. |t=normal| and the identifier must be a reserved word.
  921. @p function id_lookup(@!t:eight_bits):name_pointer; {finds current identifier}
  922. label found;
  923. var i:0..long_buf_size; {index into |buffer|}
  924. @!h:0..hash_size; {hash code}
  925. @!k:0..max_bytes; {index into |byte_mem|}
  926. @!w:0..ww-1; {row of |byte_mem|}
  927. @!l:0..long_buf_size; {length of the given identifier}
  928. @!p:name_pointer; {where the identifier is being sought}
  929. begin l:=id_loc-id_first; {compute the length}
  930. @<Compute the hash code |h|@>;
  931. @<Compute the name location |p|@>;
  932. if p=name_ptr then @<Enter a new name into the table at position |p|@>;
  933. id_lookup:=p;
  934. @ A simple hash code is used: If the sequence of
  935. ASCII codes is $c_1c_2\ldots c_m$, its hash value will be
  936. $$(2^{n-1}c_1+2^{n-2}c_2+\cdots+c_n)\,\bmod\,|hash_size|.$$
  937. @<Compute the hash...@>=
  938. h:=buffer[id_first]; i:=id_first+1;
  939. while i<id_loc do
  940.   begin h:=(h+h+buffer[i]) mod hash_size; incr(i);
  941.   end
  942. ?endgroup % end of verbatim mode
  943. \endgroup
  944. \vfill\eject
  945. \def\runninghead{APPENDIX B --- TRANSLATION BY {\tentt WEAVE}}
  946. \section Appendix B.
  947. This excerpt from \.{WEAVE.TEX} corresponds to Appendix A.
  948. % I've inserted \vfill's here at the blank lines, to squeeze this on one page!
  949. \begingroup \def\tt{\eighttt} \baselineskip9pt
  950. \verbatim
  951. ?vfill?verbatimgobble
  952. \N55.  Searching for identifiers.
  953. The hash table described above is updated by the \\{id\_lookup} procedure,
  954. which finds a given identifier and returns a pointer to its index in
  955. \\{byte\_start}. The identifier is supposed to match character by character
  956. and it is also supposed to have a given \\{ilk} code; the same name may be
  957. present more than once if it is supposed to appear in the index with
  958. different typesetting conventions.
  959. If the identifier was not already present, it is inserted into the table.
  960. ?vfill?verbatimgobble
  961. Because of the way \.{WEAVE}'s scanning mechanism works, it is most convenient
  962. to let \\{id\_lookup} search for an identifier that is present in the %
  963. \\{buffer}
  964. array. Two other global variables specify its position in the buffer: the
  965. first character is $\\{buffer}[\\{id\_first}]$, and the last is $\\{buffer}[%
  966. \\{id\_loc}-1]$.
  967. ?vfill?verbatimgobble
  968. \Y\P$\4\X9:Globals in the outer block\X\mathrel{+}\S$\6
  969. \4\\{id\_first}: \37$0\to\\{long\_buf\_size}$;\C{where the current identifier
  970. begins in the buffer}\6
  971. \4\\{id\_loc}: \37$0\to\\{long\_buf\_size}$;\C{just after the current
  972. identifier in the buffer}\7
  973. \4\\{hash}: \37\&{array} $[0\to\\{hash\_size}]$ \1\&{of}\5
  974. \\{sixteen\_bits};\C{heads of hash lists}\2\par
  975. ?vfill?verbatimgobble
  976. \M56. Initially all the hash lists are empty.
  977. ?vfill?verbatimgobble
  978. \Y\P$\4\X16:Local variables for initialization\X\mathrel{+}\S$\6
  979. \4\|h: \37$0\to\\{hash\_size}$;\C{index into hash-head array}\par
  980. ?vfill?verbatimgobble
  981. \M57. \P$\X10:Set initial values\X\mathrel{+}\S$\6
  982. \&{for} $\|h\K0\mathrel{\&{to}}\\{hash\_size}-1$ \1\&{do}\5
  983. $\\{hash}[\|h]\K0$;\2\par
  984. ?vfill?verbatimgobble
  985. \M58. Here now is the main procedure for finding identifiers (and index
  986. entries).  The parameter \|t is set to the desired \\{ilk} code. The
  987. identifier must either have $\\{ilk}=\|t$, or we must have
  988. $\|t=\\{normal}$ and the identifier must be a reserved word.
  989. ?vfill?verbatimgobble
  990. \Y\P\4\&{function}\1\  \37$\\{id\_lookup}(\|t:\\{eight\_bits})$: \37\\{name%
  991. \_pointer};\C{finds current identifier}\6
  992. \4\&{label} \37\\{found};\6
  993. \4\&{var} \37\|i: \37$0\to\\{long\_buf\_size}$;\C{index into \\{buffer}}\6
  994. \|h: \37$0\to\\{hash\_size}$;\C{hash code}\6
  995. \|k: \37$0\to\\{max\_bytes}$;\C{index into \\{byte\_mem}}\6
  996. \|w: \37$0\to\\{ww}-1$;\C{row of \\{byte\_mem}}\6
  997. \|l: \37$0\to\\{long\_buf\_size}$;\C{length of the given identifier}\6
  998. \|p: \37\\{name\_pointer};\C{where the identifier is being sought}\2\6
  999. \&{begin} \37$\|l\K\\{id\_loc}-\\{id\_first}$;\C{compute the length}\6
  1000. \X59:Compute the hash code \|h\X;\6
  1001. \X60:Compute the name location \|p\X;\6
  1002. \&{if} $\|p=\\{name\_ptr}$ \1\&{then}\5
  1003. \X62:Enter a new name into the table at position \|p\X;\2\6
  1004. $\\{id\_lookup}\K\|p$;\6
  1005. \&{end};\par
  1006. ?vfill?verbatimgobble
  1007. \M59. A simple hash code is used: If the sequence of
  1008. ASCII codes is $c_1c_2\ldots c_m$, its hash value will be
  1009. $$(2^{n-1}c_1+2^{n-2}c_2+\cdots+c_n)\,\bmod\,\\{hash\_size}.$$
  1010. ?vfill?verbatimgobble
  1011. \Y\P$\4\X59:Compute the hash code \|h\X\S$\6
  1012. $\|h\K\\{buffer}[\\{id\_first}]$;\5
  1013. $\|i\K\\{id\_first}+1$;\6
  1014. \&{while} $\|i<\\{id\_loc}$ \1\&{do}\6
  1015. \&{begin} \37$\|h\K(\|h+\|h+\\{buffer}[\|i])\mathbin{\&{mod}}\\{hash\_size}$;\5
  1016. $\\{incr}(\|i)$;\6
  1017. \&{end}\2\par
  1018. \U section~58.\fi
  1019. ?endgroup
  1020. \endgroup
  1021. \eject
  1022. \def\runninghead{APPENDIX C --- TRANSLATION BY {\tentt TANGLE}}
  1023. \section Appendix C.
  1024. The \.{TANGLE} processor converts \.{WEAVE.WEB} into a syntactically
  1025. correct (but not very pretty) \PASCAL\ program \.{WEAVE.PAS}.
  1026. The first three and last two lines of output are shown here, together with the
  1027. lines of code generated by modules 55--62 and the environments of
  1028. those lines. There are 1559 lines in all; the notation
  1029. `\.. \\. \\.' stands for portions that are not shown.
  1030. Note that, for example, the code corresponding to
  1031. module 55 begins with `\.{\{55:\}}' and ends with `\.{\{:55\}}';
  1032. the code from modules 59--62 has been tangled into the code from module 58.
  1033. \vskip6pt
  1034. \verbatim
  1035. {2:}{4:}{$C-,A+,D-}{[$C+,D+]}{:4}
  1036. PROGRAM WEAVE(WEBFILE,CHANGEFILE,TEXFILE);LABEL 9999;CONST{8:}
  1037. MAXBYTES=45000;MAXNAMES=5000;MAXMODULES=2000;HASHSIZE=353;BUFSIZE=100;
  1038.      . . .
  1039. TOKPTR:0..MAXTOKS;{MAXTOKPTR,MAXTXTPTR:0..MAXTOKS;}{:53}{55:}
  1040. IDFIRST:0..LONGBUFSIZE;IDLOC:0..LONGBUFSIZE;
  1041. HASH:ARRAY[0..HASHSIZE]OF SIXTEENBITS;{:55}{63:}CURNAME:NAMEPOINTER;
  1042.      . . .
  1043. PROCEDURE INITIALIZE;VAR{16:}I:0..127;{:16}{40:}WI:0..1;{:40}{56:}
  1044. H:0..HASHSIZE;{:56}{247:}C:ASCIICODE;{:247}BEGIN{10:}HISTORY:=0;{:10}
  1045.      . . .
  1046. TOKPTR:=1;TEXTPTR:=1;TOKSTART[0]:=1;TOKSTART[1]:=1;{MAXTOKPTR:=1;
  1047. MAXTXTPTR:=1;}{:54}{57:}FOR H:=0 TO HASHSIZE-1 DO HASH[H]:=0;{:57}{94:}
  1048. SCANNINGHEX:=FALSE;{:94}{102:}MODTEXT[0]:=32;{:102}{124:}OUTPTR:=1;
  1049.      . . .
  1050. IF R=0 THEN XREF[P]:=XREFPTR ELSE XMEM[R].XLINKFIELD:=XREFPTR;END;{:51}
  1051. {58:}FUNCTION IDLOOKUP(T:EIGHTBITS):NAMEPOINTER;LABEL 31;
  1052. VAR I:0..LONGBUFSIZE;H:0..HASHSIZE;K:0..MAXBYTES;W:0..1;
  1053. L:0..LONGBUFSIZE;P:NAMEPOINTER;BEGIN L:=IDLOC-IDFIRST;{59:}
  1054. H:=BUFFER[IDFIRST];I:=IDFIRST+1;
  1055. WHILE I<IDLOC DO BEGIN H:=(H+H+BUFFER[I])MOD HASHSIZE;I:=I+1;END{:59};
  1056. {60:}P:=HASH[H];
  1057. WHILE P<>0 DO BEGIN IF(BYTESTART[P+2]-BYTESTART[P]=L)AND((ILK[P]=T)OR((T
  1058. =0)AND(ILK[P]>3)))THEN{61:}BEGIN I:=IDFIRST;K:=BYTESTART[P];W:=P MOD 2;
  1059. WHILE(I<IDLOC)AND(BUFFER[I]=BYTEMEM[W,K])DO BEGIN I:=I+1;K:=K+1;END;
  1060. IF I=IDLOC THEN GOTO 31;END{:61};P:=LINK[P];END;P:=NAMEPTR;
  1061. LINK[P]:=HASH[H];HASH[H]:=P;31:{:60};IF P=NAMEPTR THEN{62:}
  1062. BEGIN W:=NAMEPTR MOD 2;
  1063. IF BYTEPTR[W]+L>MAXBYTES THEN BEGIN WRITELN(TERMOUT);
  1064. WRITE(TERMOUT,'! Sorry, ','byte memory',' capacity exceeded');ERROR;
  1065. HISTORY:=3;JUMPOUT;END;
  1066. IF NAMEPTR+2>MAXNAMES THEN BEGIN WRITELN(TERMOUT);
  1067. WRITE(TERMOUT,'! Sorry, ','name',' capacity exceeded');ERROR;HISTORY:=3;
  1068. JUMPOUT;END;I:=IDFIRST;K:=BYTEPTR[W];
  1069. WHILE I<IDLOC DO BEGIN BYTEMEM[W,K]:=BUFFER[I];K:=K+1;I:=I+1;END;
  1070. BYTEPTR[W]:=K;BYTESTART[NAMEPTR+2]:=K;NAMEPTR:=NAMEPTR+1;ILK[P]:=T;
  1071. XREF[P]:=0;END{:62};IDLOOKUP:=P;END;{:58}{66:}
  1072. FUNCTION MODLOOKUP(L:SIXTEENBITS):NAMEPOINTER;LABEL 31;VAR C:0..4;
  1073.      . . .
  1074. WRITE(TERMOUT,'(That was a fatal error, my friend.)');END;END{:263};
  1075. END.{:261}
  1076. ?endgroup
  1077. \vfill\eject
  1078. \pageno=199 % take account of the page numbers for App's D and E.
  1079. \def\runninghead{APPENDIX F --- MACROS FOR FORMATTING}
  1080. \section Appendix F: The \.{webmac.tex} file.
  1081. This is the file that extends ``plain \TeX'' format in order to support the
  1082. features needed by the output of \.{WEAVE}.
  1083. \vskip6pt
  1084. \verbatim
  1085. % standard macros for WEB listings (in addition to PLAIN.TEX)
  1086. \xdef\fmtversion{\fmtversion+WEBMAC1.4} % identifies current set of macros
  1087. \parskip 0pt % no stretch between paragraphs
  1088. \parindent 1em % for paragraphs and for the first line of Pascal text
  1089. \font\eightrm=cmr8
  1090. \let\sc=\eightrm \let\mainfont=\tenrm
  1091. \font\titlefont=cmr7 scaled\magstep4 % title on the contents page
  1092. \font\ttitlefont=cmtt10 scaled\magstep2 % typewriter type in title
  1093. \font\tentex=cmtex10 % TeX extended character set (used in strings)
  1094. \def\\#1{\hbox{\it#1\/\kern.05em}} % italic type for identifiers
  1095. \def\|#1{\hbox{$#1$}} % one-letter identifiers look a bit better this way
  1096. \def\{\hbox{\bf#1\/}} % boldface type for reserved words
  1097. \def\.#1{\hbox{\tentex % typewriter type for strings
  1098.   \let\\=\BS % backslash in a string
  1099.   \let\'=\RQ % right quote in a string
  1100.   \let\`=\LQ % left quote in a string
  1101.   \let\{=\LB % left brace in a string
  1102.   \let\}=\RB % right brace in a string
  1103.   \let\~=\TL % tilde in a string
  1104.   \let\ =\SP % space in a string
  1105.   \let\_=\UL % underline in a string
  1106.   \let\&=\AM % ampersand in a string
  1107.   #1}}
  1108. \def\#{\hbox{\tt\char`\#}} % parameter sign
  1109. \def\${\hbox{\tt\char`\$}} % dollar sign
  1110. \def\%{\hbox{\tt\char`\%}} % percent sign
  1111. \def\^{\ifmmode\mathchar"222 \else\char`^ \fi} % pointer or hat
  1112. % circumflex accents can be obtained from \^^D instead of \^
  1113. \def\AT!{@} % at sign for control text
  1114. \chardef\AM=`\& % ampersand character in a string
  1115. \chardef\BS=`\\ % backslash in a string
  1116. \chardef\LB=`\{ % left brace in a string
  1117. \def\LQ{{\tt\char'22}} % left quote in a string
  1118. \chardef\RB=`\} % right brace in a string
  1119. \def\RQ{{\tt\char'23}} % right quote in a string
  1120. \def\SP{{\tt\char`\ }} % (visible) space in a string
  1121. \chardef\TL=`\~ % tilde in a string
  1122. \chardef\UL=`\_ % underline character in a string
  1123. \newbox\bak \setbox\bak=\hbox to -1em{} % backspace one em
  1124. \newbox\bakk\setbox\bakk=\hbox to -2em{} % backspace two ems
  1125. \newcount\ind % current indentation in ems
  1126. \def\1{\global\advance\ind by1\hangindent\ind em} % indent one more notch
  1127. \def\2{\global\advance\ind by-1} % indent one less notch
  1128. \def\3#1{\hfil\penalty#10\hfilneg} % optional break within a statement
  1129. \def\4{\copy\bak} % backspace one notch
  1130. \def\5{\hfil\penalty-1\hfilneg\kern2.5em\copy\bakk\ignorespaces}% optional break
  1131. \def\6{\ifmmode\else\par % forced break
  1132.   \hangindent\ind em\noindent\kern\ind em\copy\bakk\ignorespaces\fi}
  1133. \def\7{\Y\6} % forced break and a little extra space
  1134. \let\yskip=\smallskip
  1135. \def\to{\mathrel{.\,.}} % double dot, used only in math mode
  1136. \def\note#1#2.{\Y\noindent{\hangindent2em\baselineskip10pt\eightrm#1 #2.\par}}
  1137. \def\lapstar{\rlap{*}}
  1138. \def\startsection{\Q\noindent{\let\*=\lapstar\bf\modstar.\quad}}
  1139. \def\defin#1{\global\advance\ind by 2 \1\&{#1 }} % begin `define' or `format'
  1140. \def\A{\note{See also}} % cross-reference for multiply defined section names
  1141. \def\B{\mathopen{\.{@\{}}} % begin controlled comment
  1142. \def\C#1{\ifmmode\gdef\XX{\null$\null}\else\gdef\XX{}\fi % Pascal comments
  1143.   \XX\hfil\penalty-1\hfilneg\quad$\{\,$#1$\,\}$\XX}
  1144. \def\D{\defin{define}} % macro definition
  1145. \def\E{\cdot10^} % exponent in floating point constant
  1146. \def\F{\defin{format}} % format definition
  1147. \let\G=\ge % greater than or equal sign
  1148. \def\H#1{\hbox{\rm\char"7D\tt#1}} % hexadecimal constant
  1149. \let\I=\ne % unequal sign
  1150. \def\J{\.{@\&}} % TANGLE's join operation
  1151. \let\K=\gets % left arrow
  1152. \let\L=\le % less than or equal sign
  1153. \outer\def\M#1.{\MN#1.\ifon\vfil\penalty-100\vfilneg % beginning of section
  1154.   \vskip12ptminus3pt\startsection\ignorespaces}
  1155. \outer\def\N#1.#2.{\MN#1.\vfil\eject % beginning of starred section
  1156.   \def\rhead{\uppercase{\ignorespaces#2}} % define running headline
  1157.   \message{*\modno} % progress report
  1158.   \edef\next{\write\cont{\Z{#2}{\modno}{\the\pageno}}}\next % to contents file
  1159.   \ifon\startsection{\bf\ignorespaces#2.\quad}\ignorespaces}
  1160. \def\MN#1.{\par % common code for \M, \N
  1161.   {\xdef\modstar{#1}\let\*=\empty\xdef\modno{#1}}
  1162.   \ifx\modno\modstar \onmaybe \else\ontrue \fi \mark{\modno}}
  1163. \def\O#1{\hbox{\rm\char'23\kern-.2em\it#1\/\kern.05em}} % octal constant
  1164. \def\P{\rightskip=0pt plus 100pt minus 10pt % go into Pascal mode
  1165.   \sfcode`;=3000
  1166.   \pretolerance 10000
  1167.   \hyphenpenalty 10000 \exhyphenpenalty 10000
  1168.   \global\ind=2 \1\ \unskip}
  1169. \def\Q{\rightskip=0pt % get out of Pascal mode
  1170.   \sfcode`;=1500 \pretolerance 200 \hyphenpenalty 50 \exhyphenpenalty 50 }
  1171. \let\R=\lnot % logical not
  1172. \let\S=\equiv % equivalence sign
  1173. \def\T{\mathclose{\.{@\}}}} % terminate controlled comment
  1174. \def\U{\note{This code is used in}} % cross-reference for uses of sections
  1175. \let\V=\lor % logical or
  1176. \let\W=\land % logical and
  1177. \def\X#1:#2\X{\ifmmode\gdef\XX{\null$\null}\else\gdef\XX{}\fi % section name
  1178.   \XX$\langle\,$#2{\eightrm\kern.5em#1}$\,\rangle$\XX}
  1179. \def\Y{\par\yskip}
  1180. \let\Z=\let % now you can \send the control sequence \Z
  1181. \def\){\hbox{\.{@\$}}} % sign for string pool check sum
  1182. \def\]{\hbox{\.{@\\}}} % sign for forced line break
  1183. \def\=#1{\kern2pt\hbox{\vrule\vtop{\vbox{\hrule
  1184.         \hbox{\strut\kern2pt\.{#1}\kern2pt}}
  1185.       \hrule}\vrule}\kern2pt} % verbatim string
  1186. \let\~=\ignorespaces
  1187. \let\*=*
  1188. \def\onmaybe{\let\ifon=\maybe} \let\maybe=\iftrue
  1189. \newif\ifon \newif\iftitle \newif\ifpagesaved
  1190. \def\lheader{\mainfont\the\pageno\eightrm\qquad\rhead\hfill\title\qquad
  1191.   \tensy x\mainfont\topmark} % top line on left-hand pages
  1192. \def\rheader{\tensy x\mainfont\topmark\eightrm\qquad\title\hfill\rhead
  1193.   \qquad\mainfont\the\pageno} % top line on right-hand pages
  1194. \def\page{\box255 }
  1195. \def\normaloutput#1#2#3{\ifodd\pageno\hoffset=\pageshift\fi
  1196.   \shipout\vbox{
  1197.     \vbox to\fullpageheight{
  1198.       \iftitle\global\titlefalse
  1199.       \else\hbox to\pagewidth{\vbox to10pt{}\ifodd\pageno #3\else#2\fi}\fi
  1200.       \vfill#1}} % parameter #1 is the page itself
  1201.   \global\advance\pageno by1}
  1202. \def\rhead{\.{WEB} OUTPUT} % this running head is reset by starred sections
  1203. \def\title{} % an optional title can be set by the user
  1204. \def\topofcontents{\centerline{\titlefont\title}
  1205.   \vfill} % this material will start the table of contents page
  1206. \def\botofcontents{\vfill} % this material will end the table of contents page
  1207. \def\contentspagenumber{0} % default page number for table of contents
  1208. \newdimen\pagewidth \pagewidth=6.5in % the width of each page
  1209. \newdimen\pageheight \pageheight=8.7in % the height of each page
  1210. \newdimen\fullpageheight \fullpageheight=9in % page height including headlines
  1211. \newdimen\pageshift \pageshift=0in % shift righthand pages wrt lefthand ones
  1212. \def\magnify#1{\mag=#1\pagewidth=6.5truein\pageheight=8.7truein
  1213.   \fullpageheight=9truein\setpage}
  1214. \def\setpage{\hsize\pagewidth\vsize\pageheight} % use after changing page size
  1215. \def\contentsfile{CONTENTS} % file that gets table of contents info
  1216. \def\readcontents{\input CONTENTS}
  1217. \newwrite\cont
  1218. \output{\setbox0=\page % the first page is garbage
  1219.   \openout\cont=\contentsfile
  1220.   \global\output{\normaloutput\page\lheader\rheader}}
  1221. \setpage
  1222. \vbox to \vsize{} % the first \topmark won't be null
  1223. \def\ch{\note{The following sections were changed by the change file:}
  1224.   \let\*=\relax}
  1225. \newbox\sbox % saved box preceding the index
  1226. \newbox\lbox % lefthand column in the index
  1227. \def\inx{\par\vskip6pt plus 1fil % we are beginning the index
  1228.   \write\cont{} % ensure that the contents file isn't empty
  1229.   \closeout\cont % the contents information has been fully gathered
  1230.   \output{\ifpagesaved\normaloutput{\box\sbox}\lheader\rheader\fi
  1231.     \global\setbox\sbox=\page \global\pagesavedtrue}
  1232.   \pagesavedfalse \eject % eject the page-so-far and predecessors
  1233.   \setbox\sbox\vbox{\unvbox\sbox} % take it out of its box
  1234.   \vsize=\pageheight \advance\vsize by -\ht\sbox % the remaining height
  1235.   \hsize=.5\pagewidth \advance\hsize by -10pt
  1236.     % column width for the index (20pt between cols)
  1237.   \parfillskip 0pt plus .6\hsize % try to avoid almost empty lines
  1238.   \def\lr{L} % this tells whether the left or right column is next
  1239.   \output{\if L\lr\global\setbox\lbox=\page \gdef\lr{R}
  1240.     \else\normaloutput{\vbox to\pageheight{\box\sbox\vss
  1241.         \hbox to\pagewidth{\box\lbox\hfil\page}}}\lheader\rheader
  1242.     \global\vsize\pageheight\gdef\lr{L}\global\pagesavedfalse\fi}
  1243.   \message{Index:}
  1244.   \parskip 0pt plus .5pt
  1245.   \outer\def\:##1, {\par\hangindent2em\noindent##1:\kern1em} % index entry
  1246.   \let\ttentry=\. \def\.##1{\ttentry{##1\kern.2em}} % give \tt a little room
  1247.   \def\[##1]{$\underline{##1}$} % underlined index item
  1248.   \rm \rightskip0pt plus 2.5em \tolerance 10000 \let\*=\lapstar
  1249.   \hyphenpenalty 10000 \parindent0pt}
  1250. \def\fin{\par\vfill\eject % this is done when we are ending the index
  1251.   \ifpagesaved\null\vfill\eject\fi % output a null index column
  1252.   \if L\lr\else\null\vfill\eject\fi % finish the current page
  1253.   \parfillskip 0pt plus 1fil
  1254.   \def\rhead{NAMES OF THE SECTIONS}
  1255.   \message{Section names:}
  1256.   \output{\normaloutput\page\lheader\rheader}
  1257.   \setpage
  1258.   \def\note##1##2.{\hfil\penalty-1\hfilneg\quad{\eightrm##1 ##2.}}
  1259.   \linepenalty=10 % try to conserve lines
  1260.   \def\U{\note{Used in}} % cross-reference for uses of sections
  1261.   \def\:{\par\hangindent 2em}\let\*=*\let\.=\ttentry}
  1262. \def\con{\par\vfill\eject % finish the section names
  1263.   \rightskip 0pt \hyphenpenalty 50 \tolerance 200
  1264.   \setpage
  1265.   \output{\normaloutput\page\lheader\rheader}
  1266.   \titletrue % prepare to output the table of contents
  1267.   \pageno=\contentspagenumber \def\rhead{TABLE OF CONTENTS}
  1268.   \message{Table of contents:}
  1269.   \topofcontents
  1270.   \line{\hfil Section\hbox to3em{\hss Page}}
  1271.   \def\Z##1##2##3{\line{\ignorespaces##1
  1272.     \leaders\hbox to .5em{.\hfil}\hfil\ ##2\hbox to3em{\hss##3}}}
  1273.   \readcontents\relax % read the contents info
  1274.   \botofcontents \end} % print the contents page(s) and terminate
  1275. ?endgroup
  1276. \vfill\eject
  1277. \def\runninghead{APPENDIX G --- NOTES ON FORMATTING}
  1278. \section Appendix G: How to use \.{WEB} macros.
  1279. The macros in \.{webmac} make it possible to produce a variety of formats
  1280. without editing the output of \.{WEAVE}, and the purpose of this appendix
  1281. is to explain some of the possibilities.
  1282. \def\point#1.{\yskip\indent#1.\quad\ignorespaces}
  1283. \point 1. Three fonts have been declared in addition to the standard fonts of
  1284. \.{PLAIN} format: You can say `\.{\{\\sc stuff\}}' to get {\sc STUFF}
  1285. in small caps; and you can select the largish fonts \.{\\titlefont}
  1286. and \.{\\ttitlefont} in the title of your document, where \.{\\ttitlefont}
  1287. is a typewriter style of type.
  1288. \point 2. When you mention an identifier in \TeX\ text, you normally call
  1289. it `\.{|identifier|}'. But you can also say `\.{\\\\\{identifier\}}'. The
  1290. output will look the same in both cases, but the second alternative
  1291. doesn't put \\{identifier} into the index, since
  1292. it bypasses \.{WEAVE}'s translation from \PASCAL\ mode.
  1293. \point 3. To get typewriter-like type, as when referring to `\.{WEB}', you
  1294. can use the `\.{\\.}' macro (e.g., `\.{\\.\{WEB\}}'). In the argument to
  1295. this macro you should insert an additional backslash before the symbols
  1296. listed as `special string characters' in the index to \.{WEAVE}, i.e.,
  1297. before backslashes and dollar signs and the like.
  1298. A `\.{\\\ }' here will result in the visible space symbol; to get an
  1299. invisible space following a control sequence you can say `\.{\{\ \}}'.
  1300. \point 4. The three control sequences \.{\\pagewidth}, \.{\\pageheight},
  1301. and \.{\\fullpageheight} can be redefined in the limbo section at the
  1302. beginning of your \.{WEB} file, to change the dimensions of each page.
  1303. The standard settings
  1304. $$\lpile{\.{\\pagewidth=6.5in}\cr
  1305.   \.{\\pageheight=8.7in}\cr
  1306.   \.{\\fullpageheight=9in}\cr}$$
  1307. were used to prepare the present report; \.{\\fullpageheight} is
  1308. \.{\\pageheight} plus room for the additional heading and page numbers at
  1309. the top of each page. If you change any of these quantities, you should
  1310. call the macro \.{\\setpage} immediately after making the change.
  1311. \point 5. The \.{\\pageshift} macro defines an amount by which right-hand
  1312. pages (i.e., odd-numbered pages) are shifted right with respect to
  1313. left-hand (even-numbered) ones. By adjusting this amount you may be
  1314. able to get two-sided output in which the page numbers line up on
  1315. opposite sides of each sheet.
  1316. \point 6. The \.{\\title} macro will appear at the top of each page
  1317. in small caps. For example, Appendix~D was produced after saying
  1318. `\.{\\def\\title\{WEAVE\}}'.
  1319. \point 7. The first page usually is number 1; if you want some other
  1320. starting page, just set \.{\\pageno} to the desired number. For example,
  1321. the initial limbo section for Appendix~D included the command
  1322. `\.{\\pageno=16}'.
  1323. \point 8. The macro \.{\\iftitle} will suppress the header line if it is
  1324. defined by `\.{\\titletrue}'. The normal value is \.{\\titlefalse}
  1325. except for the table of contents; thus, the contents
  1326. page is usually unnumbered. If your program is so long that the table of
  1327. contents doesn't fit on a single page, or if you want a number to appear
  1328. on the contents page, you should reset \.{\\pageno} when you begin the
  1329. table of contents.
  1330. Two macros are provided to give flexibility to the table of
  1331. contents: \.{\\topofcontents} is invoked just before the contents
  1332. info is read, and \.{\\botofcontents} is invoked just after.
  1333. For example, Appendix~D was produced with the following definitions:
  1334. $$\lpile{\.{\\def\\topofcontents\{\\null\\vfill}\cr
  1335.   \.{ { }\\titlefalse \% include headline on the contents page}\cr
  1336.   \.{ { }\\def\\rheader\{\\mainfont Appendix D\\hfil 15\}}\cr
  1337.   \.{ { }\\centerline\{\\titlefont The \{\\ttitlefont WEAVE\}{ }processor\}}\cr
  1338.   \.{ { }\\vskip 15pt \\centerline\{(Version 2.5)\}{ }\\vfill\}}\cr}$$
  1339. Redefining \.{\\rheader}, which is the headline for right-hand pages,
  1340. suffices in this case to put the desired information at the top of the page.
  1341. \point 9. Data for the table of contents is written to a file that
  1342. is read after the indexes have been \TeX ed; there's one line of data
  1343. for every starred module. For example, when Appendix~D was being generated,
  1344. a file \.{CONTENTS.TEX} containing
  1345. $$\lpile{\.{\\Z \{{ }Introduction\}\{1\}\{16\}}\cr
  1346.   \.{\\Z \{{ }The character set\}\{11\}\{19\}}\cr}$$
  1347. and similar lines was created. The \.{\\topofcontents} macro could
  1348. redefine \.{\\Z} so that the information appears in another format.
  1349. \point 10. Sometimes it is necessary or desirable to divide the output of
  1350. \.{WEAVE} into subfiles that can be processed separately. For example,
  1351. the listing of \TeX\ runs to more than 500 pages, and that is enough to
  1352. exceed the capacity of many printing devices and/or their software.
  1353. When an extremely large job isn't cut into smaller pieces, the entire
  1354. process might be spoiled by a single error of some sort, making it
  1355. necessary to start everything over.
  1356. Here's a safe way to break a woven file into three parts:
  1357. Say the pieces are $\alpha$,
  1358. $\beta$, and $\gamma$, where each piece begins with a starred module.
  1359. All macros should be defined in the opening limbo section of $\alpha$,
  1360. and copies of this \TeX\ code should be placed at the
  1361. beginning of $\beta$ and of $\gamma$. In order to process the parts
  1362. separately, we need to take care of two things: The starting page
  1363. numbers of $\beta$ and $\gamma$ need to be set up properly, and
  1364. the table of contents data from all three runs needs to be
  1365. accumulated.
  1366. The \.{webmac} macros include two control sequences \.{\\contentsfile} and
  1367. \.{\\readcontents} that facilitate the necessary processing.  We include
  1368. `\.{\\def\\contentsfile\{CONT1\}}' in the limbo section of $\alpha$, and
  1369. we include `\.{\\def\\contentsfile\{CONT2\}}' in the limbo section of
  1370. $\beta$; this causes \TeX\ to write the contents data for $\alpha$ and $\beta$
  1371. into \.{CONT1.TEX} and \.{CONT2.TEX}. Now in $\gamma$ we say
  1372. $$\.{\\def\\readcontents\{\\input CONT1 \\input CONT2 \\input CONTENTS\}};$$
  1373. this brings in the data from all three pieces, in the proper order.
  1374. However, we still need to solve the page-numbering problem. One way to
  1375. do it is to include the following in the limbo material for $\beta$:
  1376. $$\lpile{\.{\\message\{Please type the last page number of part 1: \}}\cr
  1377.   \.{\\read-1to\\\\ \\pageno=\\\\ \\advance\\pageno by 1}\cr}$$
  1378. Then you simply provide the necessary data when \TeX\ requests
  1379. it; a similar construction is used at the beginning of $\gamma$.
  1380. This method can, of course, be used to divide a woven file into
  1381. any number of pieces.
  1382. \point 11. Sometimes it is nice to include things in the index that are
  1383. typeset in a special way. For example, we might want to have an
  1384. index entry for `\TeX'. \.{WEAVE} provides only two standard ways to
  1385. typeset an index entry (unless the entry is an identifier or a reserved word):
  1386. `\.{@\^}' gives roman type, and `\.{@.}' gives typewriter type.
  1387. But if we try to typeset `\TeX' in roman type by saying, e.g.,
  1388. `\.{@\^\\TeX@>}', the backslash character gets in the way,
  1389. and this entry wouldn't appear in the index with the T's.
  1390. The solution is to use the `\.{@:}' feature, declaring a macro that
  1391. simply removes a sort key as follows:
  1392. $$\.{\\def\\9\#1\{\}}$$
  1393. Now you can say, e.g., `\.{@:TeX\}\{\\TeX@>}' in your \.{WEB} file; \.{WEAVE}
  1394. puts it into the index alphabetically, based on the sort key, and
  1395. produces the macro call `\.{\\9\{TeX\}\{\\TeX\}}' which will ensure that
  1396. the sort key isn't printed.
  1397. A similar idea can be used to insert hidden material into module
  1398. names so that they are alphabetized in whatever way you might wish.
  1399. Some people call these tricks ``special refinements''; others call
  1400. them ``kludges''.
  1401. \point 12. The control sequence \.{\\modno} is set to the number of the
  1402. module being typeset.
  1403. \point 13. If you want to list only the modules that have changed,
  1404. together with the index, put the command `\.{\\let\\maybe=\\iffalse}' in
  1405. the limbo section before the first module of your \.{WEB} file. It's
  1406. customary to make this the first change in your change file.
  1407. \vfill\eject
  1408. \def\runninghead{APPENDIX H --- GETTING STARTED}
  1409. \section Appendix H: Installing the \.{WEB} system.
  1410. Suppose you want to use the \.{WEB} programs on your computer, and suppose
  1411. that you can't simply borrow them from somebody else who has the same
  1412. kind of machine. Here's what to do:
  1413. \yskip
  1414. \def\step(#1){\par\hangindent 2em\noindent\hbox to 2em{\hfil(#1) }\ignorespaces}
  1415. \step(1) Get a tape that contains the files \.{WEAVE.WEB}, \.{TANGLE.WEB},
  1416. \.{TANGLE.PAS}, and \.{WEBMAC.TEX}. The tape will probably also contain an
  1417. example change file \.{TANGLE.CH}.
  1418. \step(2) Look at the sections of \.{TANGLE} that are listed under ``system
  1419. dependencies'' in the index of Appendix~E above, and figure out what changes
  1420. (if any) will be needed for your system.
  1421. \step(3) Make a change file \.{TANGLE.CH} that contains the changes of~(2);
  1422. do not change your copy of \.{TANGLE.WEB}, leave it intact. (The
  1423. rules for change files are explained at the end of the manual just before
  1424. the appendices; you may want to look at the example change file that
  1425. arrived with your copy of \.{TANGLE.WEB}. It's also a good idea to
  1426. define all the ``switches'' like \&{debug} and \&{gubed} to be null in your
  1427. first change files; then you can sure that your compiler will handle
  1428. all of the code.)
  1429. \step(4) Make the changes of (2) in your copy of \.{TANGLE.PAS}. (If these
  1430. changes are extensive, you might be better off finding some computer that
  1431. that already has \.{TANGLE} running, and making the new \.{TANGLE.PAS}
  1432. from \.{TANGLE.WEB} and your \.{TANGLE.CH}.)
  1433. \step(5) Use your \PASCAL\ compiler to convert your copy of \.{TANGLE.PAS}
  1434. to a running program \.{TANGLE}.
  1435. \step(6) Check your changes as follows: Run \.{TANGLE} on \.{TANGLE.WEB}
  1436. and your \.{TANGLE.CH}, yielding $\.{TANGLE.PAS}'$; make a running
  1437. program $\.{TANGLE}'$ by applying \PASCAL\ to
  1438. $\.{TANGLE.PAS}'$; run $\.{TANGLE}'$ on \.{TANGLE.WEB} and
  1439. your \.{TANGLE.CH}, yielding $\.{TANGLE.PAS}''$; and check
  1440. that $\.{TANGLE.PAS}''$ is identical to
  1441. $\.{TANGLE.PAS}'$. Once this test has been passed, you have got a
  1442. working \.{TANGLE} program.
  1443. \step(7) Make a change file \.{WEAVE.CH} analogous to (3), but this time
  1444. consider the system-dependent parts of \.{WEAVE} that are listed in
  1445. the index to Appendix~D.
  1446. \step(8) Run \.{TANGLE} on \.{WEAVE.WEB} and your \.{WEAVE.CH}, obtaining
  1447. \.{WEAVE.PAS}.
  1448. \step(9) Use \PASCAL\ on \.{WEAVE.PAS} to make a running \.{WEAVE} program.
  1449. \step(10) Run \.{WEAVE} on \.{TANGLE.WEB} and \.{TANGLE.CH} to produce
  1450. \.{TANGLE.TEX}.
  1451. \step(11) Run \TeX\ on \.{TANGLE.TEX}, obtaining a listing analogous to
  1452. Appendix~E. This listing will incorporate your changes.
  1453. \step(12) Run \.{WEAVE} on \.{WEAVE.WEB} and your \.{WEAVE.CH} to produce
  1454. \.{WEAVE.TEX}.
  1455. \step(13) Run \TeX\ on \.{WEAVE.TEX}, obtaining a listing analogous to
  1456. Appendix~D that incorporates your changes.
  1457. \yskip\noindent
  1458. This description assumes that you already have a working \TeX82 system.
  1459. But what if you don't have \TeX82? Then you start with a tape that also
  1460. contains \.{TEX.WEB} and \.{plain.tex}, and you refer to a hardcopy
  1461. listing of the \TeX82 program corresponding to \.{TEX.WEB}. Between steps
  1462. (10) and (11) you do the following:
  1463. \yskip
  1464. \def\substep(10.#1){\par\hangindent 4em\noindent
  1465.   \hbox to 4em{\hfil(10.#1) }\ignorespaces}
  1466. \substep(10.1) Make a change file \.{TEX.CH} to fix the system dependent
  1467. portions of \.{TEX.WEB}, in a manner analogous to step~(2). Since \TeX\ is
  1468. a much more complex program than \.{WEAVE} or \.{TANGLE}, there are more
  1469. system-dependent features to think about, but by now you will be good at
  1470. making such modifications. Do not make any changes to \.{TEX.WEB}.
  1471. \substep(10.2) Make an almost-copy of your \.{TEX.CH} called \.{INITEX.CH};
  1472. this one will have the `\&{init}' and `\&{tini}' macros redefined in order
  1473. to make the initialization version of \TeX. It also might have smaller
  1474. font memory and dynamic memory areas, since \.{INITEX} doesn't need as
  1475. much memory for such things; by setting the memory smaller in \.{INITEX},
  1476. you guarantee that the production system will have a ``cushion.''
  1477. \substep(10.3) Run \.{TANGLE} on \.{TEX.WEB} and \.{INITEX.CH}, obtaining
  1478. \.{INITEX.PAS} and \.{TEX.POOL}.
  1479. \substep(10.4) Run \PASCAL\ on \.{INITEX.PAS}, obtaining \.{INITEX}.
  1480. \substep(10.5) Run \.{INITEX} on \.{TEX.POOL}, during which run you type
  1481. `\.{plain}' and `\.{\\dump}'. This will produce a file \.{plain.fmt}
  1482. containing the data needed to initialize \TeX's memory.
  1483. \substep(10.6) Run \.{TANGLE} on \.{TEX.WEB} and the \.{TEX.CH} of (10.1),
  1484. obtaining \.{TEX.PAS}.
  1485. \substep(10.7) Run \PASCAL\ on \.{TEX.PAS}, obtaining \.{VIRTEX}.
  1486. \substep(10.8) If your operating system supports programs whose core images
  1487. have been saved, run \.{VIRTEX}, type `\.{\&plain}', then save the core image
  1488. and call it \TeX. Otherwise, \.{VIRTEX} will be your \TeX, and it will
  1489. read `\.{plain.fmt}' (or some other \.{fmt} file) each time you run.
  1490. \yskip
  1491. This 21-step process may seem long, but it is actually an oversimplification,
  1492. since you also need fonts and a way to print the device-independent files
  1493. that \TeX\ spews out. On the other hand, the total number of steps is not
  1494. quite so large when you consider that \.{TANGLE}-followed-by-\PASCAL\ and
  1495. \.{WEAVE}-followed-by-\TeX\ may be regarded as single operations.
  1496. If you have only the present report, not a tape, you will have to prepare
  1497. files \.{WEAVE.WEB} and \.{TANGLE.WEB} by hand, typing them into the
  1498. computer by following Appendices D and E. Then you have to simulate the
  1499. behavior of \.{TANGLE} by converting \.{TANGLE.WEB} manually into
  1500. \.{TANGLE.PAS}; with a good text editor this takes about six hours. Then
  1501. you have to correct errors that were made in all this hand work; but still
  1502. the whole project is not impossibly difficult, because in fact the entire
  1503. development of \.{WEAVE} and \.{TANGLE} (including the writing of the
  1504. programs and the manual) took less than two months of work.
  1505. \vfill\eject
  1506. %%% TPWEB
  1507. \eject
  1508. \def\runninghead{APPENDIX I --- Features and caveats of \TGLTP}
  1509. \section The Inline Assembler.
  1510. The Inline assembler in \TGLTP\ is a modification of the inline
  1511. assembler from L. David Baldwin usually found in
  1512. \.{<MSDOS.TURBOPAS>INLINE219.ARC}. The following is an excerpt
  1513. from his documentation \.{INLINE.DOC}:
  1514. \def\beginverbatim{\vskip 6pt\begingroup \def\tt{\eighttt} \baselineskip9pt\verbatim}
  1515. \point 1. Turbo Pascal symbols may be used within instruction entries by
  1516. preceding the symbol with a `\.{>}' (16 bit symbol) or a `\.{<}' (8  bit
  1517. symbol). The characters `\.{+}' and  `\.{-}' are considered part of  the
  1518. symbol. This allows  computations using symbols  to be passed  on to the
  1519. compiler where the computation can be made. For instance, in
  1520. \beginverbatim
  1521.                  MOV AX,[>SYMBOL+4]       ;'>SYMBOL+4' is passed on
  1522.                  MOV AX,[BP+>SYMBOL+4]    ;again '>SYMBOL+4' is passed on
  1523.                  MOV AX,>SYMBOL+4[BP]     ;also acceptable
  1524. ?endgroup
  1525. \endgroup
  1526. Note that \.{MOV  AX,[>SYMBOL+4+BP]} is not  correct since the  wrong
  1527. instruction will be generated and '\.{>SYMBOL+4+BP}' will be passed on.
  1528. \point 2. Labels (for use with jump instructions) may be defined  simply
  1529. by appending a '\.{:}' to the first item on a line. Avoid using \.{CS:},
  1530. \.{DS:},  \.{ES:},  and  \.{SS:}  as  labels,  as  these specify segment
  1531. overrides.
  1532. \point 3.  Characters within  single quotes  may be  used for  numerical
  1533. entries as: \.{CMP AL,'a'}
  1534. \point 4.  Square brackets  are used  to indicate  `contents of'.  If no
  1535. square brackets are used, an immediate operand is assumed.
  1536. \beginverbatim
  1537.                  MOV AX,[>DATA]  ;Load AX with the contents of DATA.
  1538.                  MOV AX,>DATA    ;Load AX with DATA.
  1539. ?endgroup
  1540. \endgroup
  1541. \point 5. Instruction prefixes and segment override prefixes may precede
  1542. the instruction on the same line or may be included on a previous  line.
  1543. A colon is optional after the segment prefix.
  1544. \beginverbatim
  1545.                  ES: MOV AX,[1234]    ;ok
  1546.                  REPNE MOVSB          ;ok
  1547.                  MOV AX,ES:[1234]     ;incorrect syntax
  1548. ?endgroup
  1549. \endgroup
  1550. \point 6. Instructions which don't clearly specify the data size require
  1551. that  \.{BYTE  PTR},  \.{WORD  PTR},  \.{DWORD  PTR},  \.{QWORD PTR}, or
  1552. \.{TBYTE PTR} be used. These may  be abbreviated by using the first  two
  1553. letters.
  1554. \beginverbatim
  1555.                  INC BYTE PTR [>BDATA]
  1556.                  DEC WO >WARRAY[DI]
  1557.                  FLD QWORD [>DBL_REAL]
  1558. ?endgroup
  1559. \endgroup
  1560. \point 7. \.{JMP} instructions  may use \.{SHORT}, \.{NEAR},  or \.{FAR}
  1561. (they should not be abbreviated). In the absence of one of these  words,
  1562. a \.{SHORT}  jump will  be encoded  if the  label is  already defined and is
  1563. within range. If the  label is not defined,  a \.{NEAR JMP} will  be encoded
  1564. unless \.{SHORT} is used.
  1565. A \.{FAR CALL}  or \.{JMP} may  be made to  a direct address  by stating
  1566. both the segment and offset separated by a colon: \.{CALL FAR \$1234:\$5678}
  1567. \point 8. Comments are inlcuded in the pascal output if the \.{/c} command line
  1568. switch is used.
  1569. \point 9. 8086/8088 Opcode Mnemonics Recognized by \TGLTP:
  1570. \beginverbatim
  1571.       AAA       HLT       JNE       LOOPNZ    ROR
  1572.       AAD       IDIV      JNG       LOOPZ     SAHF
  1573.       AAM       IMUL      JNGE      MOV       SAL
  1574.       AAS       IN        JNL       MOVSB     SAR
  1575.       ADC       INC       JNLE      MOVSW     SBB
  1576.       ADD       INT       JNO       MUL       SCASB
  1577.       AND       INTO      JNP       NEG       SCASW
  1578.       CALL      IRET      JNS       NOP       SHL
  1579.       CBW       JA        JNZ       NOT       SHR
  1580.       CLC       JAE       JO        OR        SS
  1581.       CLD       JB        JP        OUT       STC
  1582.       CLI       JBE       JPE       POP       STD
  1583.       CMC       JC        JPO       POPF      STI
  1584.       CMP       JCXZ      JS        PUSH      STOSB
  1585.       CMPSB     JE        JZ        PUSHF     STOSW
  1586.       CMPSW     JG        LAHF      RCL       SUB
  1587.       CS        JGE       LDS       RCR       TEST
  1588.       CWD       JL        LEA       REP       WAIT
  1589.       DAA       JLE       LES       REPE      XCHG
  1590.       DAS       JMP       LOCK      REPNE     XLAT
  1591.       DB        JNA       LODSB     REPNZ     XOR
  1592.       DEC       JNAE      LODSW     REPZ
  1593.       DIV       JNB       LOOP      RET
  1594.       DS        JNBE      LOOPE     RETF
  1595.       ES        JNC       LOOPNE    ROL
  1596. ?endgroup
  1597. \endgroup
  1598. \point 10. 8087 Opcode Mnemonics Recognized by \TGLTP:
  1599. \beginverbatim
  1600.       F2XM1     FDIVRP    FLD       FNOP      FSTP
  1601.       FABS      FENI      FLD1      FNSAVE    FSTSW
  1602.       FADD      FFREE     FLDCW     FNSTCW    FSUB
  1603.       FADDP     FIADD     FLDENV    FNSTENV   FSUBP
  1604.       FBLD      FICOM     FLDL2E    FNSTSW    FSUBR
  1605.       FBSTP     FICOMP    FLDL2T    FPATAN    FSUBRP
  1606.       FCHS      FIDIV     FLDLG2    FPREM     FTST
  1607.       FCLEX     FIDIVR    FLDLN2    FPTAN     FXAM
  1608.       FCOM      FILD      FLDPI     FRNDINT   FXCH
  1609.       FCOMP     FIMUL     FLDZ      FRSTOR    FXTRACT
  1610.       FCOMPP    FINCSTP   FMUL      FSAVE     FYL2X
  1611.       FDECSTP   FINIT     FMULP     FSCALE    FYL2XP1
  1612.       FDISI     FIST      FNCLEX    FSQRT     FWAIT
  1613.       FDIV      FISTP     FNDISI    FST
  1614.       FDIVP     FISUB     FNENI     FSTCW
  1615.       FDIVR     FISUBR    FNINIT    FSTENV
  1616. ?endgroup
  1617. \endgroup
  1618. \yskip
  1619. The inline assembler can be used with the following macro definition:
  1620. \beginverbatim
  1621. @d Asm(#)==@[#@]
  1622. ?endgroup
  1623. \endgroup
  1624. \yskip
  1625. This is preliminary. In the next version the \.{Asm} function will be
  1626. `hard-wired'.
  1627. \vfill\eject
  1628. \section Multiple change files in \TGLTP.
  1629. \TGLTP\ provides multiple change files. To use this feature
  1630. simply start \TGLTP\ with the following command line:
  1631. \beginverbatim
  1632. TANGLE webfile changefile1 changefile2 changefile3 [...changefileN]
  1633. ?endgroup
  1634. \endgroup
  1635. \yskip
  1636. Please notice that it is possible for \.{changefile2} to change
  1637. \.{webfile} as well as \.{changefile1}.
  1638. \section \TGLTP\ output optimization.
  1639. \TGLTP\ is able to optimize the \.{DIV} and \.{MOD} operations
  1640. for you:
  1641. \point 1. constructions like \.{`a div 128'} are converted to \.{`a shr 7'}
  1642. \point 2. constructions like \.{`a mod 16'} are converted to \.{`a and 15'}
  1643. \yskip\noindent
  1644. Use the \.{/d} and \.{/m} command line switches to enable
  1645. this feature.
  1646. \section  Array-like  macros.  \TGLTP\  has  another  kind of macro, the
  1647. array-like macro:
  1648. \yskip`\.{@d} \\{identifier}\.{[\#] ==} \PASCAL\ text'
  1649. defines an {\sl array-like\/} macro, where the array identifier will  be
  1650. replaced by the  \PASCAL\ text and  where occurrences of  \.{\#} in that
  1651. \PASCAL\ text will be replaced  by the array `argument'. This  is useful
  1652. when  replacing  large  arrays  like  the  \.{`mem'}  array  in \TeX\ by
  1653. function  calls.
  1654. \yskip\noindent
  1655. The  following implementation  of  the  \.{`mem'} array in \TeX
  1656. is a good example how array-like macros and the inline assembler
  1657. can be combined:
  1658. \beginverbatim
  1659. @d Asm(#)==inline(@[#@])
  1660. @d mem[#]==memp(#)^
  1661. @p type
  1662.      p_memory_word: ^memory_word;
  1663.    var
  1664.      membase: word; {segment of mem array}
  1665.    function memp (i: word):p_memory_word; @/
  1666.    Asm(pop dx/      {get 'array' index}
  1667.        xor ax,ax/   {assume Ofs(mem) 0}
  1668.        xchg al,dl/  {Low Byte of i for Ofs, High Byte for Seg}
  1669.        mov cl,2/
  1670.        shl ax,cl/   {generate Ofs}
  1671.        shr dx,cl    {generate Seg}
  1672.        add dx,word ptr [membase+2]); {return pointer in AX:DX}
  1673. ?endgroup
  1674. \endgroup
  1675. %%% TPWEB
  1676. \vfill\end
  1677.